-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathstorage_desktop.h
More file actions
145 lines (111 loc) · 4.85 KB
/
storage_desktop.h
File metadata and controls
145 lines (111 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef FIREBASE_STORAGE_SRC_DESKTOP_STORAGE_DESKTOP_H_
#define FIREBASE_STORAGE_SRC_DESKTOP_STORAGE_DESKTOP_H_
#include <string>
#include <vector>
#include "app/src/future_manager.h"
#include "app/src/include/firebase/internal/mutex.h"
#include "storage/src/desktop/storage_path.h"
#include "storage/src/desktop/storage_reference_desktop.h"
#include "storage/src/include/firebase/storage/common.h"
namespace firebase {
namespace storage {
namespace internal {
class RestOperation;
class StorageInternal {
public:
// Build a Storage. A nullptr or empty url uses the default getInstance.
StorageInternal(App* app, const char* url);
~StorageInternal();
// Get the firease::App that this Storage was created with.
::firebase::App* app() { return app_; }
// Return the URL we were created with, if we were created with it explicitly.
std::string url() { return url_; }
// Get a StorageReference to the root of the database.
StorageReferenceInternal* GetReference();
// Get a StorageReference for the specified path.
StorageReferenceInternal* GetReference(const char* path);
// Get a StorageReference for the provided URL.
StorageReferenceInternal* GetReferenceFromUrl(const char* url);
// Returns the maximum time (in seconds) to retry a download if a failure
// occurs.
double max_download_retry_time() { return max_download_retry_time_; }
// Sets the maximum time (in seconds) to retry a download if a failure occurs.
void set_max_download_retry_time(double max_download_retry_time) {
max_download_retry_time_ = max_download_retry_time;
}
// Returns the maximum time (in seconds) to retry an upload if a failure
// occurs.
double max_upload_retry_time() { return max_upload_retry_time_; }
// Sets the maximum time (in seconds) to retry an upload if a failure occurs.
void set_max_upload_retry_time(double max_upload_retry_time) {
max_upload_retry_time_ = max_upload_retry_time;
}
// Returns the maximum time (in seconds) to retry operations other than upload
// and download if a failure occurs.
double max_operation_retry_time() { return max_operation_retry_time_; }
// Sets the maximum time (in seconds) to retry operations other than upload
// and download if a failure occurs.
void set_max_operation_retry_time(double max_operation_retry_time) {
max_operation_retry_time_ = max_operation_retry_time;
}
// Whether this object was successfully initialized by the constructor.
bool initialized() const { return app_ != nullptr; }
// When this is deleted, it will clean up all StorageReferences and other
// objects.
FutureManager& future_manager() { return future_manager_; }
CleanupNotifier& cleanup() { return cleanup_; }
// Fetches the auth token (if available) from app via the function callback
// registry. If not available, it returns an empty string.
std::string GetAuthToken();
// Get the user agent to send with storage requests.
const std::string& user_agent() const { return user_agent_; }
// Add an operation to the list of outstanding operations.
void AddOperation(RestOperation* operation);
// Remove an operation from the list of outstanding operations.
void RemoveOperation(RestOperation* operation);
// Configures the Storage SDK to use an emulated backend instead of call the
// default remote backend
void UseEmulator(const char* host, int port);
// Returns the Host for the storage backend
std::string get_host() { return host_; }
// Returns the Port for the storage backend
int get_port() { return port_; }
// Returns the url scheme currenly in use for the storage backend
std::string get_scheme() { return scheme_; }
private:
// Clean up completed operations.
void CleanupCompletedOperations();
private:
App* app_;
FutureManager future_manager_;
std::string url_;
double max_download_retry_time_;
double max_operation_retry_time_;
double max_upload_retry_time_;
StoragePath root_;
CleanupNotifier cleanup_;
std::string user_agent_;
Mutex operations_mutex_;
std::vector<RestOperation*> operations_;
std::string host_ = "firebasestorage.googleapis.com";
std::string scheme_ = "https";
int port_ = 443;
bool configured_ = false;
};
} // namespace internal
} // namespace storage
} // namespace firebase
#endif // FIREBASE_STORAGE_SRC_DESKTOP_STORAGE_DESKTOP_H_