| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_file_system/drive_backend_v1/api_util.h" | 5 #include "chrome/browser/sync_file_system/drive_backend_v1/api_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/drive/drive_api_service.h" | 18 #include "chrome/browser/drive/drive_api_service.h" |
| 19 #include "chrome/browser/drive/drive_api_util.h" | 19 #include "chrome/browser/drive/drive_api_util.h" |
| 20 #include "chrome/browser/drive/drive_uploader.h" | 20 #include "chrome/browser/drive/drive_uploader.h" |
| 21 #include "chrome/browser/drive/gdata_wapi_service.h" | 21 #include "chrome/browser/drive/gdata_wapi_service.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 23 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 25 #include "chrome/browser/signin/signin_manager.h" | |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 27 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
h" | 25 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
h" |
| 28 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.
h" | 26 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.
h" |
| 29 #include "chrome/browser/sync_file_system/logger.h" | 27 #include "chrome/browser/sync_file_system/logger.h" |
| 30 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 28 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
| 31 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 32 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
| 33 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 34 #include "google_apis/drive/drive_api_parser.h" | 32 #include "google_apis/drive/drive_api_parser.h" |
| 35 #include "google_apis/drive/drive_api_url_generator.h" | 33 #include "google_apis/drive/drive_api_url_generator.h" |
| 36 #include "google_apis/drive/gdata_wapi_url_generator.h" | 34 #include "google_apis/drive/gdata_wapi_url_generator.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT, | 150 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT, |
| 153 base::MessageLoopProxy::current().get()); | 151 base::MessageLoopProxy::current().get()); |
| 154 return success; | 152 return success; |
| 155 } | 153 } |
| 156 | 154 |
| 157 } // namespace | 155 } // namespace |
| 158 | 156 |
| 159 APIUtil::APIUtil(Profile* profile, | 157 APIUtil::APIUtil(Profile* profile, |
| 160 const base::FilePath& temp_dir_path) | 158 const base::FilePath& temp_dir_path) |
| 161 : oauth_service_(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)), | 159 : oauth_service_(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)), |
| 162 signin_manager_(SigninManagerFactory::GetForProfile(profile)), | |
| 163 upload_next_key_(0), | 160 upload_next_key_(0), |
| 164 temp_dir_path_(temp_dir_path), | 161 temp_dir_path_(temp_dir_path), |
| 165 has_initialized_token_(false) { | 162 has_initialized_token_(false) { |
| 166 base::SequencedWorkerPool* blocking_pool = | 163 base::SequencedWorkerPool* blocking_pool = |
| 167 content::BrowserThread::GetBlockingPool(); | 164 content::BrowserThread::GetBlockingPool(); |
| 168 scoped_refptr<base::SequencedTaskRunner> task_runner( | 165 scoped_refptr<base::SequencedTaskRunner> task_runner( |
| 169 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken())); | 166 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken())); |
| 170 if (IsDriveAPIDisabled()) { | 167 if (IsDriveAPIDisabled()) { |
| 171 drive_service_.reset(new drive::GDataWapiService( | 168 drive_service_.reset(new drive::GDataWapiService( |
| 172 oauth_service_, | 169 oauth_service_, |
| 173 profile->GetRequestContext(), | 170 profile->GetRequestContext(), |
| 174 task_runner.get(), | 171 task_runner.get(), |
| 175 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 172 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 176 GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction), | 173 GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction), |
| 177 std::string() /* custom_user_agent */)); | 174 std::string() /* custom_user_agent */)); |
| 178 } else { | 175 } else { |
| 179 drive_service_.reset(new drive::DriveAPIService( | 176 drive_service_.reset(new drive::DriveAPIService( |
| 180 oauth_service_, | 177 oauth_service_, |
| 181 profile->GetRequestContext(), | 178 profile->GetRequestContext(), |
| 182 task_runner.get(), | 179 task_runner.get(), |
| 183 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), | 180 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), |
| 184 GURL(google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction), | 181 GURL(google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction), |
| 185 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 182 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 186 std::string() /* custom_user_agent */)); | 183 std::string() /* custom_user_agent */)); |
| 187 } | 184 } |
| 188 | 185 |
| 189 drive_service_->Initialize(signin_manager_->GetAuthenticatedAccountId()); | 186 drive_service_->Initialize(oauth_service_->GetPrimaryAccountId()); |
| 190 drive_service_->AddObserver(this); | 187 drive_service_->AddObserver(this); |
| 191 has_initialized_token_ = drive_service_->HasRefreshToken(); | 188 has_initialized_token_ = drive_service_->HasRefreshToken(); |
| 192 | 189 |
| 193 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 190 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 194 | 191 |
| 195 drive_uploader_.reset(new drive::DriveUploader( | 192 drive_uploader_.reset(new drive::DriveUploader( |
| 196 drive_service_.get(), content::BrowserThread::GetBlockingPool())); | 193 drive_service_.get(), content::BrowserThread::GetBlockingPool())); |
| 197 } | 194 } |
| 198 | 195 |
| 199 scoped_ptr<APIUtil> APIUtil::CreateForTesting( | 196 scoped_ptr<APIUtil> APIUtil::CreateForTesting( |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 656 } |
| 660 | 657 |
| 661 // static | 658 // static |
| 662 GURL APIUtil::DirectoryTitleToOrigin(const std::string& title) { | 659 GURL APIUtil::DirectoryTitleToOrigin(const std::string& title) { |
| 663 return extensions::Extension::GetBaseURLFromExtensionId(title); | 660 return extensions::Extension::GetBaseURLFromExtensionId(title); |
| 664 } | 661 } |
| 665 | 662 |
| 666 void APIUtil::OnReadyToSendRequests() { | 663 void APIUtil::OnReadyToSendRequests() { |
| 667 DCHECK(CalledOnValidThread()); | 664 DCHECK(CalledOnValidThread()); |
| 668 if (!has_initialized_token_) { | 665 if (!has_initialized_token_) { |
| 669 drive_service_->Initialize(signin_manager_->GetAuthenticatedAccountId()); | 666 drive_service_->Initialize(oauth_service_->GetPrimaryAccountId()); |
| 670 has_initialized_token_ = true; | 667 has_initialized_token_ = true; |
| 671 } | 668 } |
| 672 FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnAuthenticated()); | 669 FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnAuthenticated()); |
| 673 } | 670 } |
| 674 | 671 |
| 675 void APIUtil::OnConnectionTypeChanged( | 672 void APIUtil::OnConnectionTypeChanged( |
| 676 net::NetworkChangeNotifier::ConnectionType type) { | 673 net::NetworkChangeNotifier::ConnectionType type) { |
| 677 DCHECK(CalledOnValidThread()); | 674 DCHECK(CalledOnValidThread()); |
| 678 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) { | 675 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 679 FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnNetworkConnected()); | 676 FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnNetworkConnected()); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 } | 1131 } |
| 1135 | 1132 |
| 1136 std::string APIUtil::GetRootResourceId() const { | 1133 std::string APIUtil::GetRootResourceId() const { |
| 1137 if (IsDriveAPIDisabled()) | 1134 if (IsDriveAPIDisabled()) |
| 1138 return drive_service_->GetRootResourceId(); | 1135 return drive_service_->GetRootResourceId(); |
| 1139 return root_resource_id_; | 1136 return root_resource_id_; |
| 1140 } | 1137 } |
| 1141 | 1138 |
| 1142 } // namespace drive_backend | 1139 } // namespace drive_backend |
| 1143 } // namespace sync_file_system | 1140 } // namespace sync_file_system |
| OLD | NEW |