| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 243 } |
| 244 | 244 |
| 245 // The resource ID for the root directory for Drive API is defined in the spec: | 245 // The resource ID for the root directory for Drive API is defined in the spec: |
| 246 // https://developers.google.com/drive/folder | 246 // https://developers.google.com/drive/folder |
| 247 const char kDriveApiRootDirectoryResourceId[] = "root"; | 247 const char kDriveApiRootDirectoryResourceId[] = "root"; |
| 248 | 248 |
| 249 } // namespace | 249 } // namespace |
| 250 | 250 |
| 251 DriveAPIService::DriveAPIService( | 251 DriveAPIService::DriveAPIService( |
| 252 OAuth2TokenService* oauth2_token_service, | 252 OAuth2TokenService* oauth2_token_service, |
| 253 const std::string& account_id, |
| 253 net::URLRequestContextGetter* url_request_context_getter, | 254 net::URLRequestContextGetter* url_request_context_getter, |
| 254 base::TaskRunner* blocking_task_runner, | 255 base::TaskRunner* blocking_task_runner, |
| 255 const GURL& base_url, | 256 const GURL& base_url, |
| 256 const GURL& base_download_url, | 257 const GURL& base_download_url, |
| 257 const GURL& wapi_base_url, | 258 const GURL& wapi_base_url, |
| 258 const std::string& custom_user_agent) | 259 const std::string& custom_user_agent) |
| 259 : oauth2_token_service_(oauth2_token_service), | 260 : oauth2_token_service_(oauth2_token_service), |
| 261 account_id_(account_id), |
| 260 url_request_context_getter_(url_request_context_getter), | 262 url_request_context_getter_(url_request_context_getter), |
| 261 blocking_task_runner_(blocking_task_runner), | 263 blocking_task_runner_(blocking_task_runner), |
| 262 url_generator_(base_url, base_download_url), | 264 url_generator_(base_url, base_download_url), |
| 263 wapi_url_generator_(wapi_base_url, base_download_url), | 265 wapi_url_generator_(wapi_base_url, base_download_url), |
| 264 custom_user_agent_(custom_user_agent) { | 266 custom_user_agent_(custom_user_agent) { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 } | 268 } |
| 267 | 269 |
| 268 DriveAPIService::~DriveAPIService() { | 270 DriveAPIService::~DriveAPIService() { |
| 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 270 if (sender_.get()) | 272 if (sender_.get()) |
| 271 sender_->auth_service()->RemoveObserver(this); | 273 sender_->auth_service()->RemoveObserver(this); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void DriveAPIService::Initialize() { | 276 void DriveAPIService::Initialize() { |
| 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 276 | 278 |
| 277 std::vector<std::string> scopes; | 279 std::vector<std::string> scopes; |
| 278 scopes.push_back(kDriveScope); | 280 scopes.push_back(kDriveScope); |
| 279 scopes.push_back(kDriveAppsReadonlyScope); | 281 scopes.push_back(kDriveAppsReadonlyScope); |
| 280 | 282 |
| 281 // GData WAPI token. These are for GetShareUrl(). | 283 // GData WAPI token. These are for GetShareUrl(). |
| 282 scopes.push_back(util::kDocsListScope); | 284 scopes.push_back(util::kDocsListScope); |
| 283 scopes.push_back(util::kDriveAppsScope); | 285 scopes.push_back(util::kDriveAppsScope); |
| 284 | 286 |
| 285 sender_.reset(new RequestSender( | 287 sender_.reset(new RequestSender( |
| 286 new google_apis::AuthService( | 288 new google_apis::AuthService(oauth2_token_service_, |
| 287 oauth2_token_service_, url_request_context_getter_, scopes), | 289 account_id_, |
| 288 url_request_context_getter_, | 290 url_request_context_getter_, |
| 289 blocking_task_runner_.get(), | 291 scopes), |
| 290 custom_user_agent_)); | 292 url_request_context_getter_, |
| 293 blocking_task_runner_.get(), |
| 294 custom_user_agent_)); |
| 291 sender_->auth_service()->AddObserver(this); | 295 sender_->auth_service()->AddObserver(this); |
| 292 } | 296 } |
| 293 | 297 |
| 294 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { | 298 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { |
| 295 observers_.AddObserver(observer); | 299 observers_.AddObserver(observer); |
| 296 } | 300 } |
| 297 | 301 |
| 298 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { | 302 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { |
| 299 observers_.RemoveObserver(observer); | 303 observers_.RemoveObserver(observer); |
| 300 } | 304 } |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 if (CanSendRequest()) { | 834 if (CanSendRequest()) { |
| 831 FOR_EACH_OBSERVER( | 835 FOR_EACH_OBSERVER( |
| 832 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 836 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
| 833 } else if (!HasRefreshToken()) { | 837 } else if (!HasRefreshToken()) { |
| 834 FOR_EACH_OBSERVER( | 838 FOR_EACH_OBSERVER( |
| 835 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 839 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
| 836 } | 840 } |
| 837 } | 841 } |
| 838 | 842 |
| 839 } // namespace drive | 843 } // namespace drive |
| OLD | NEW |