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/drive/drive_api_service.h" | 5 #include "chrome/browser/drive/drive_api_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" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 302 } |
303 | 303 |
304 // The resource ID for the root directory for Drive API is defined in the spec: | 304 // The resource ID for the root directory for Drive API is defined in the spec: |
305 // https://developers.google.com/drive/folder | 305 // https://developers.google.com/drive/folder |
306 const char kDriveApiRootDirectoryResourceId[] = "root"; | 306 const char kDriveApiRootDirectoryResourceId[] = "root"; |
307 | 307 |
308 } // namespace | 308 } // namespace |
309 | 309 |
310 DriveAPIService::DriveAPIService( | 310 DriveAPIService::DriveAPIService( |
311 OAuth2TokenService* oauth2_token_service, | 311 OAuth2TokenService* oauth2_token_service, |
| 312 const std::string& account_id, |
312 net::URLRequestContextGetter* url_request_context_getter, | 313 net::URLRequestContextGetter* url_request_context_getter, |
313 base::TaskRunner* blocking_task_runner, | 314 base::TaskRunner* blocking_task_runner, |
314 const GURL& base_url, | 315 const GURL& base_url, |
315 const GURL& base_download_url, | 316 const GURL& base_download_url, |
316 const GURL& wapi_base_url, | 317 const GURL& wapi_base_url, |
317 const std::string& custom_user_agent) | 318 const std::string& custom_user_agent) |
318 : oauth2_token_service_(oauth2_token_service), | 319 : oauth2_token_service_(oauth2_token_service), |
| 320 account_id_(account_id), |
319 url_request_context_getter_(url_request_context_getter), | 321 url_request_context_getter_(url_request_context_getter), |
320 blocking_task_runner_(blocking_task_runner), | 322 blocking_task_runner_(blocking_task_runner), |
321 url_generator_(base_url, base_download_url), | 323 url_generator_(base_url, base_download_url), |
322 wapi_url_generator_(wapi_base_url, base_download_url), | 324 wapi_url_generator_(wapi_base_url, base_download_url), |
323 custom_user_agent_(custom_user_agent) { | 325 custom_user_agent_(custom_user_agent) { |
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
325 } | 327 } |
326 | 328 |
327 DriveAPIService::~DriveAPIService() { | 329 DriveAPIService::~DriveAPIService() { |
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
329 if (sender_.get()) | 331 if (sender_.get()) |
330 sender_->auth_service()->RemoveObserver(this); | 332 sender_->auth_service()->RemoveObserver(this); |
331 } | 333 } |
332 | 334 |
333 void DriveAPIService::Initialize() { | 335 void DriveAPIService::Initialize() { |
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
335 | 337 |
336 std::vector<std::string> scopes; | 338 std::vector<std::string> scopes; |
337 scopes.push_back(kDriveScope); | 339 scopes.push_back(kDriveScope); |
338 scopes.push_back(kDriveAppsReadonlyScope); | 340 scopes.push_back(kDriveAppsReadonlyScope); |
339 | 341 |
340 // GData WAPI token. These are for GetShareUrl(). | 342 // GData WAPI token. These are for GetShareUrl(). |
341 scopes.push_back(util::kDocsListScope); | 343 scopes.push_back(util::kDocsListScope); |
342 scopes.push_back(util::kDriveAppsScope); | 344 scopes.push_back(util::kDriveAppsScope); |
343 | 345 |
344 sender_.reset(new RequestSender( | 346 sender_.reset(new RequestSender( |
345 new google_apis::AuthService( | 347 new google_apis::AuthService(oauth2_token_service_, |
346 oauth2_token_service_, url_request_context_getter_, scopes), | 348 account_id_, |
347 url_request_context_getter_, | 349 url_request_context_getter_, |
348 blocking_task_runner_.get(), | 350 scopes), |
349 custom_user_agent_)); | 351 url_request_context_getter_, |
| 352 blocking_task_runner_.get(), |
| 353 custom_user_agent_)); |
350 sender_->auth_service()->AddObserver(this); | 354 sender_->auth_service()->AddObserver(this); |
351 } | 355 } |
352 | 356 |
353 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { | 357 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { |
354 observers_.AddObserver(observer); | 358 observers_.AddObserver(observer); |
355 } | 359 } |
356 | 360 |
357 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { | 361 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { |
358 observers_.RemoveObserver(observer); | 362 observers_.RemoveObserver(observer); |
359 } | 363 } |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 if (CanSendRequest()) { | 873 if (CanSendRequest()) { |
870 FOR_EACH_OBSERVER( | 874 FOR_EACH_OBSERVER( |
871 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 875 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
872 } else if (!HasRefreshToken()) { | 876 } else if (!HasRefreshToken()) { |
873 FOR_EACH_OBSERVER( | 877 FOR_EACH_OBSERVER( |
874 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 878 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
875 } | 879 } |
876 } | 880 } |
877 | 881 |
878 } // namespace drive | 882 } // namespace drive |
OLD | NEW |