OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/google_apis/gdata_wapi_service.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "chrome/browser/google_apis/auth_service.h" | 12 #include "chrome/browser/google_apis/auth_service.h" |
13 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 13 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
| 14 #include "chrome/browser/google_apis/gdata_wapi_url_util.h" |
14 #include "chrome/browser/google_apis/operation_runner.h" | 15 #include "chrome/browser/google_apis/operation_runner.h" |
15 #include "chrome/browser/google_apis/time_util.h" | 16 #include "chrome/browser/google_apis/time_util.h" |
16 #include "chrome/common/net/url_util.h" | 17 #include "chrome/common/net/url_util.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 | 19 |
19 using content::BrowserThread; | 20 using content::BrowserThread; |
20 | 21 |
21 namespace google_apis { | 22 namespace google_apis { |
22 | 23 |
23 namespace { | 24 namespace { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 60 |
60 // OAuth2 scopes for the documents API. | 61 // OAuth2 scopes for the documents API. |
61 const char kDocsListScope[] = "https://docs.google.com/feeds/"; | 62 const char kDocsListScope[] = "https://docs.google.com/feeds/"; |
62 const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; | 63 const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; |
63 const char kUserContentScope[] = "https://docs.googleusercontent.com/"; | 64 const char kUserContentScope[] = "https://docs.googleusercontent.com/"; |
64 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; | 65 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; |
65 | 66 |
66 } // namespace | 67 } // namespace |
67 | 68 |
68 GDataWapiService::GDataWapiService() | 69 GDataWapiService::GDataWapiService() |
69 : runner_(NULL) { | 70 : runner_(NULL), |
| 71 // TODO(satorux): The base URL should be injected. |
| 72 url_generator_(GURL(gdata_wapi_url_util::kBaseUrlForProduction)) { |
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
71 } | 74 } |
72 | 75 |
73 GDataWapiService::~GDataWapiService() { | 76 GDataWapiService::~GDataWapiService() { |
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
75 if (runner_.get()) { | 78 if (runner_.get()) { |
76 runner_->operation_registry()->RemoveObserver(this); | 79 runner_->operation_registry()->RemoveObserver(this); |
77 runner_->auth_service()->RemoveObserver(this); | 80 runner_->auth_service()->RemoveObserver(this); |
78 } | 81 } |
79 } | 82 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 bool shared_with_me, | 142 bool shared_with_me, |
140 const std::string& directory_resource_id, | 143 const std::string& directory_resource_id, |
141 const GetDataCallback& callback) { | 144 const GetDataCallback& callback) { |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
143 | 146 |
144 // Drive V2 API defines changestamp in int64, while DocumentsList API uses | 147 // Drive V2 API defines changestamp in int64, while DocumentsList API uses |
145 // int32. This narrowing should not cause any trouble. | 148 // int32. This narrowing should not cause any trouble. |
146 GetDocumentsOperation* operation = | 149 GetDocumentsOperation* operation = |
147 new google_apis::GetDocumentsOperation( | 150 new google_apis::GetDocumentsOperation( |
148 operation_registry(), | 151 operation_registry(), |
| 152 url_generator_, |
149 url, | 153 url, |
150 static_cast<int>(start_changestamp), | 154 static_cast<int>(start_changestamp), |
151 search_query, | 155 search_query, |
152 shared_with_me, | 156 shared_with_me, |
153 directory_resource_id, | 157 directory_resource_id, |
154 callback); | 158 callback); |
155 runner_->StartOperationWithRetry(operation); | 159 runner_->StartOperationWithRetry(operation); |
156 } | 160 } |
157 | 161 |
158 void GDataWapiService::GetDocumentEntry( | 162 void GDataWapiService::GetDocumentEntry( |
159 const std::string& resource_id, | 163 const std::string& resource_id, |
160 const GetDataCallback& callback) { | 164 const GetDataCallback& callback) { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
162 | 166 |
163 GetDocumentEntryOperation* operation = | 167 GetDocumentEntryOperation* operation = |
164 new GetDocumentEntryOperation(operation_registry(), | 168 new GetDocumentEntryOperation(operation_registry(), |
| 169 url_generator_, |
165 resource_id, | 170 resource_id, |
166 callback); | 171 callback); |
167 runner_->StartOperationWithRetry(operation); | 172 runner_->StartOperationWithRetry(operation); |
168 } | 173 } |
169 | 174 |
170 void GDataWapiService::GetAccountMetadata(const GetDataCallback& callback) { | 175 void GDataWapiService::GetAccountMetadata(const GetDataCallback& callback) { |
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
172 | 177 |
173 GetAccountMetadataOperation* operation = | 178 GetAccountMetadataOperation* operation = |
174 new GetAccountMetadataOperation( | 179 new GetAccountMetadataOperation( |
175 operation_registry(), callback); | 180 operation_registry(), url_generator_, callback); |
176 runner_->StartOperationWithRetry(operation); | 181 runner_->StartOperationWithRetry(operation); |
177 } | 182 } |
178 | 183 |
179 void GDataWapiService::GetApplicationInfo( | 184 void GDataWapiService::GetApplicationInfo( |
180 const GetDataCallback& callback) { | 185 const GetDataCallback& callback) { |
181 // For WAPI, AccountMetadata includes Drive application information. | 186 // For WAPI, AccountMetadata includes Drive application information. |
182 GetAccountMetadata(callback); | 187 GetAccountMetadata(callback); |
183 } | 188 } |
184 | 189 |
185 void GDataWapiService::DownloadDocument( | 190 void GDataWapiService::DownloadDocument( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 document_url)); | 230 document_url)); |
226 } | 231 } |
227 | 232 |
228 void GDataWapiService::AddNewDirectory( | 233 void GDataWapiService::AddNewDirectory( |
229 const GURL& parent_content_url, | 234 const GURL& parent_content_url, |
230 const FilePath::StringType& directory_name, | 235 const FilePath::StringType& directory_name, |
231 const GetDataCallback& callback) { | 236 const GetDataCallback& callback) { |
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
233 | 238 |
234 runner_->StartOperationWithRetry( | 239 runner_->StartOperationWithRetry( |
235 new CreateDirectoryOperation( | 240 new CreateDirectoryOperation(operation_registry(), |
236 operation_registry(), callback, parent_content_url, directory_name)); | 241 url_generator_, |
| 242 callback, |
| 243 parent_content_url, |
| 244 directory_name)); |
237 } | 245 } |
238 | 246 |
239 void GDataWapiService::CopyDocument( | 247 void GDataWapiService::CopyDocument( |
240 const std::string& resource_id, | 248 const std::string& resource_id, |
241 const FilePath::StringType& new_name, | 249 const FilePath::StringType& new_name, |
242 const GetDataCallback& callback) { | 250 const GetDataCallback& callback) { |
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
244 | 252 |
245 runner_->StartOperationWithRetry( | 253 runner_->StartOperationWithRetry( |
246 new CopyDocumentOperation(operation_registry(), callback, | 254 new CopyDocumentOperation(operation_registry(), |
247 resource_id, new_name)); | 255 url_generator_, |
| 256 callback, |
| 257 resource_id, |
| 258 new_name)); |
248 } | 259 } |
249 | 260 |
250 void GDataWapiService::RenameResource( | 261 void GDataWapiService::RenameResource( |
251 const GURL& resource_url, | 262 const GURL& resource_url, |
252 const FilePath::StringType& new_name, | 263 const FilePath::StringType& new_name, |
253 const EntryActionCallback& callback) { | 264 const EntryActionCallback& callback) { |
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
255 | 266 |
256 runner_->StartOperationWithRetry( | 267 runner_->StartOperationWithRetry( |
257 new RenameResourceOperation(operation_registry(), callback, | 268 new RenameResourceOperation(operation_registry(), callback, |
258 resource_url, new_name)); | 269 resource_url, new_name)); |
259 } | 270 } |
260 | 271 |
261 void GDataWapiService::AddResourceToDirectory( | 272 void GDataWapiService::AddResourceToDirectory( |
262 const GURL& parent_content_url, | 273 const GURL& parent_content_url, |
263 const GURL& resource_url, | 274 const GURL& resource_url, |
264 const EntryActionCallback& callback) { | 275 const EntryActionCallback& callback) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
266 | 277 |
267 runner_->StartOperationWithRetry( | 278 runner_->StartOperationWithRetry( |
268 new AddResourceToDirectoryOperation(operation_registry(), | 279 new AddResourceToDirectoryOperation(operation_registry(), |
| 280 url_generator_, |
269 callback, | 281 callback, |
270 parent_content_url, | 282 parent_content_url, |
271 resource_url)); | 283 resource_url)); |
272 } | 284 } |
273 | 285 |
274 void GDataWapiService::RemoveResourceFromDirectory( | 286 void GDataWapiService::RemoveResourceFromDirectory( |
275 const GURL& parent_content_url, | 287 const GURL& parent_content_url, |
276 const GURL& resource_url, | 288 const GURL& resource_url, |
277 const std::string& resource_id, | 289 const std::string& resource_id, |
278 const EntryActionCallback& callback) { | 290 const EntryActionCallback& callback) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 DriveServiceObserver, observers_, OnProgressUpdate(list)); | 365 DriveServiceObserver, observers_, OnProgressUpdate(list)); |
354 } | 366 } |
355 | 367 |
356 void GDataWapiService::OnAuthenticationFailed(GDataErrorCode error) { | 368 void GDataWapiService::OnAuthenticationFailed(GDataErrorCode error) { |
357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
358 FOR_EACH_OBSERVER( | 370 FOR_EACH_OBSERVER( |
359 DriveServiceObserver, observers_, OnAuthenticationFailed(error)); | 371 DriveServiceObserver, observers_, OnAuthenticationFailed(error)); |
360 } | 372 } |
361 | 373 |
362 } // namespace google_apis | 374 } // namespace google_apis |
OLD | NEW |