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