Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: chrome/browser/chromeos/gdata/drive_api_service.cc

Issue 10920091: Move Drive API files to google_apis directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix dependency problem Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/gdata/drive_api_service.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/bind.h"
11 #include "base/message_loop_proxy.h"
12 #include "chrome/browser/chromeos/gdata/drive_api_operations.h"
13 #include "chrome/browser/chromeos/gdata/gdata_operations.h"
14 #include "chrome/browser/chromeos/gdata/gdata_util.h"
15 #include "chrome/browser/chromeos/gdata/operation_runner.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/net/url_util.h"
18 #include "content/public/browser/browser_thread.h"
19
20 using content::BrowserThread;
21
22 namespace gdata {
23
24 namespace {
25
26 // OAuth2 scopes for Drive API.
27 const char kDriveScope[] = "https://www.googleapis.com/auth/drive";
28 const char kDriveAppsReadonlyScope[] =
29 "https://www.googleapis.com/auth/drive.apps.readonly";
30
31 } // namespace
32
33 DriveAPIService::DriveAPIService()
34 : profile_(NULL),
35 runner_(NULL) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 }
38
39 DriveAPIService::~DriveAPIService() {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 if (runner_.get())
42 runner_->auth_service()->RemoveObserver(this);
43 }
44
45 void DriveAPIService::Initialize(Profile* profile) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
47 profile_ = profile;
48
49 std::vector<std::string> scopes;
50 scopes.push_back(kDriveScope);
51 scopes.push_back(kDriveAppsReadonlyScope);
52 runner_.reset(new OperationRunner(profile, scopes));
53 runner_->Initialize();
54
55 runner_->auth_service()->AddObserver(this);
56 }
57
58 void DriveAPIService::AddObserver(DriveServiceObserver* observer) {
59 observers_.AddObserver(observer);
60 }
61
62 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) {
63 observers_.RemoveObserver(observer);
64 }
65
66 OperationRegistry* DriveAPIService::operation_registry() const {
67 return runner_->operation_registry();
68 }
69
70 bool DriveAPIService::CanStartOperation() const {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
72
73 return HasRefreshToken();
74 }
75
76 void DriveAPIService::CancelAll() {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 runner_->CancelAll();
79 }
80
81 void DriveAPIService::Authenticate(const AuthStatusCallback& callback) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 runner_->Authenticate(callback);
84 }
85
86 void DriveAPIService::GetDocuments(const GURL& url,
87 int64 start_changestamp,
88 const std::string& search_query,
89 const std::string& directory_resource_id,
90 const GetDataCallback& callback) {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
92
93 if (search_query.empty())
94 GetChangelist(url, start_changestamp, callback);
95 else
96 GetFilelist(url, search_query, callback);
97
98 return;
99 // TODO(kochi): Implement !directory_resource_id.empty() case.
100 NOTREACHED();
101 }
102
103 void DriveAPIService::GetFilelist(const GURL& url,
104 const std::string& search_query,
105 const GetDataCallback& callback) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
107
108 runner_->StartOperationWithRetry(
109 new GetFilelistOperation(operation_registry(),
110 url,
111 search_query,
112 callback));
113 }
114
115 void DriveAPIService::GetChangelist(const GURL& url,
116 int64 start_changestamp,
117 const GetDataCallback& callback) {
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
119
120 runner_->StartOperationWithRetry(
121 new GetChangelistOperation(operation_registry(),
122 url,
123 start_changestamp,
124 callback));
125 }
126
127 void DriveAPIService::GetDocumentEntry(const std::string& resource_id,
128 const GetDataCallback& callback) {
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
130
131 runner_->StartOperationWithRetry(new GetFileOperation(operation_registry(),
132 resource_id,
133 callback));
134 }
135
136 void DriveAPIService::GetAccountMetadata(const GetDataCallback& callback) {
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
138
139 runner_->StartOperationWithRetry(
140 new GetAboutOperation(operation_registry(), callback));
141 }
142
143 void DriveAPIService::GetApplicationInfo(const GetDataCallback& callback) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
145
146 runner_->StartOperationWithRetry(
147 new GetApplistOperation(operation_registry(), callback));
148 }
149
150 void DriveAPIService::DownloadDocument(
151 const FilePath& virtual_path,
152 const FilePath& local_cache_path,
153 const GURL& document_url,
154 DocumentExportFormat format,
155 const DownloadActionCallback& callback) {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
157
158 // TODO(kochi): Implement this.
159 NOTREACHED();
160 }
161
162 void DriveAPIService::DownloadFile(
163 const FilePath& virtual_path,
164 const FilePath& local_cache_path,
165 const GURL& document_url,
166 const DownloadActionCallback& download_action_callback,
167 const GetContentCallback& get_content_callback) {
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
169
170 // TODO(kochi): Implement this.
171 NOTREACHED();
172 }
173
174 void DriveAPIService::DeleteDocument(const GURL& document_url,
175 const EntryActionCallback& callback) {
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
177
178 // TODO(kochi): Implement this.
179 NOTREACHED();
180 }
181
182 void DriveAPIService::CreateDirectory(
183 const GURL& parent_content_url,
184 const FilePath::StringType& directory_name,
185 const GetDataCallback& callback) {
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
187
188 // TODO(kochi): Implement this.
189 NOTREACHED();
190 }
191
192 void DriveAPIService::CopyDocument(const std::string& resource_id,
193 const FilePath::StringType& new_name,
194 const GetDataCallback& callback) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
196
197 // TODO(kochi): Implement this.
198 NOTREACHED();
199 }
200
201 void DriveAPIService::RenameResource(const GURL& resource_url,
202 const FilePath::StringType& new_name,
203 const EntryActionCallback& callback) {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205
206 // TODO(kochi): Implement this.
207 NOTREACHED();
208 }
209
210 void DriveAPIService::AddResourceToDirectory(
211 const GURL& parent_content_url,
212 const GURL& resource_url,
213 const EntryActionCallback& callback) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215
216 // TODO(kochi): Implement this.
217 NOTREACHED();
218 }
219
220 void DriveAPIService::RemoveResourceFromDirectory(
221 const GURL& parent_content_url,
222 const GURL& resource_url,
223 const std::string& resource_id,
224 const EntryActionCallback& callback) {
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
226
227 // TODO(kochi): Implement this.
228 NOTREACHED();
229 }
230
231 void DriveAPIService::InitiateUpload(const InitiateUploadParams& params,
232 const InitiateUploadCallback& callback) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234
235 // TODO(kochi): Implement this.
236 NOTREACHED();
237 }
238
239 void DriveAPIService::ResumeUpload(const ResumeUploadParams& params,
240 const ResumeUploadCallback& callback) {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
242
243 // TODO(kochi): Implement this.
244 NOTREACHED();
245 }
246
247 void DriveAPIService::AuthorizeApp(const GURL& resource_url,
248 const std::string& app_ids,
249 const GetDataCallback& callback) {
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
251
252 // TODO(kochi): Implement this.
253 NOTREACHED();
254 }
255
256 bool DriveAPIService::HasAccessToken() const {
257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
258
259 return runner_->auth_service()->HasAccessToken();
260 }
261
262 bool DriveAPIService::HasRefreshToken() const {
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
264
265 return runner_->auth_service()->HasRefreshToken();
266 }
267
268 void DriveAPIService::OnOAuth2RefreshTokenChanged() {
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
270 FOR_EACH_OBSERVER(
271 DriveServiceObserver, observers_, OnOperationReadinessChanged());
272 }
273
274 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698