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