| 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> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 enum ParentType { | 38 enum ParentType { |
| 39 PARENT_TYPE_ROOT_OR_EMPTY, | 39 PARENT_TYPE_ROOT_OR_EMPTY, |
| 40 PARENT_TYPE_DIRECTORY, | 40 PARENT_TYPE_DIRECTORY, |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 const char kSyncRootDirectoryName[] = "Chrome Syncable FileSystem"; | 43 const char kSyncRootDirectoryName[] = "Chrome Syncable FileSystem"; |
| 44 const char kSyncRootDirectoryNameDev[] = "Chrome Syncable FileSystem Dev"; | 44 const char kSyncRootDirectoryNameDev[] = "Chrome Syncable FileSystem Dev"; |
| 45 const char kMimeTypeOctetStream[] = "application/octet-stream"; | 45 const char kMimeTypeOctetStream[] = "application/octet-stream"; |
| 46 | 46 |
| 47 const char kFakeAccountId[] = "test_user@gmail.com"; |
| 47 const char kFakeServerBaseUrl[] = "https://fake_server/"; | 48 const char kFakeServerBaseUrl[] = "https://fake_server/"; |
| 48 const char kFakeDownloadServerBaseUrl[] = "https://fake_download_server/"; | 49 const char kFakeDownloadServerBaseUrl[] = "https://fake_download_server/"; |
| 49 | 50 |
| 50 void EmptyGDataErrorCodeCallback(google_apis::GDataErrorCode error) {} | 51 void EmptyGDataErrorCodeCallback(google_apis::GDataErrorCode error) {} |
| 51 | 52 |
| 52 bool HasParentLinkTo(const ScopedVector<google_apis::Link>& links, | 53 bool HasParentLinkTo(const ScopedVector<google_apis::Link>& links, |
| 53 const std::string& parent_resource_id, | 54 const std::string& parent_resource_id, |
| 54 ParentType parent_type) { | 55 ParentType parent_type) { |
| 55 bool has_parent = false; | 56 bool has_parent = false; |
| 56 | 57 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 : wapi_url_generator_( | 162 : wapi_url_generator_( |
| 162 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 163 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 163 GURL(google_apis::GDataWapiUrlGenerator:: | 164 GURL(google_apis::GDataWapiUrlGenerator:: |
| 164 kBaseDownloadUrlForProduction)), | 165 kBaseDownloadUrlForProduction)), |
| 165 drive_api_url_generator_( | 166 drive_api_url_generator_( |
| 166 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), | 167 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), |
| 167 GURL(google_apis::DriveApiUrlGenerator:: | 168 GURL(google_apis::DriveApiUrlGenerator:: |
| 168 kBaseDownloadUrlForProduction)), | 169 kBaseDownloadUrlForProduction)), |
| 169 upload_next_key_(0), | 170 upload_next_key_(0), |
| 170 temp_dir_path_(temp_dir_path) { | 171 temp_dir_path_(temp_dir_path) { |
| 171 OAuth2TokenService* oauth_service = | 172 ProfileOAuth2TokenService* oauth_service = |
| 172 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 173 if (IsDriveAPIDisabled()) { | 174 if (IsDriveAPIDisabled()) { |
| 174 drive_service_.reset(new drive::GDataWapiService( | 175 drive_service_.reset(new drive::GDataWapiService( |
| 175 oauth_service, | 176 oauth_service, |
| 176 profile->GetRequestContext(), | 177 profile->GetRequestContext(), |
| 177 content::BrowserThread::GetBlockingPool(), | 178 content::BrowserThread::GetBlockingPool(), |
| 178 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 179 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 179 GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction), | 180 GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction), |
| 180 std::string() /* custom_user_agent */)); | 181 std::string() /* custom_user_agent */)); |
| 181 } else { | 182 } else { |
| 182 drive_service_.reset(new drive::DriveAPIService( | 183 drive_service_.reset(new drive::DriveAPIService( |
| 183 oauth_service, | 184 oauth_service, |
| 184 profile->GetRequestContext(), | 185 profile->GetRequestContext(), |
| 185 content::BrowserThread::GetBlockingPool(), | 186 content::BrowserThread::GetBlockingPool(), |
| 186 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), | 187 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), |
| 187 GURL(google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction), | 188 GURL(google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction), |
| 188 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 189 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 189 std::string() /* custom_user_agent */)); | 190 std::string() /* custom_user_agent */)); |
| 190 } | 191 } |
| 191 | 192 |
| 192 drive_service_->Initialize(); | 193 drive_service_->Initialize(oauth_service->GetPrimaryAccountId()); |
| 193 drive_service_->AddObserver(this); | 194 drive_service_->AddObserver(this); |
| 194 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 195 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 195 | 196 |
| 196 drive_uploader_.reset(new drive::DriveUploader( | 197 drive_uploader_.reset(new drive::DriveUploader( |
| 197 drive_service_.get(), content::BrowserThread::GetBlockingPool())); | 198 drive_service_.get(), content::BrowserThread::GetBlockingPool())); |
| 198 } | 199 } |
| 199 | 200 |
| 200 scoped_ptr<APIUtil> APIUtil::CreateForTesting( | 201 scoped_ptr<APIUtil> APIUtil::CreateForTesting( |
| 201 const base::FilePath& temp_dir_path, | 202 const base::FilePath& temp_dir_path, |
| 202 scoped_ptr<drive::DriveServiceInterface> drive_service, | 203 scoped_ptr<drive::DriveServiceInterface> drive_service, |
| 203 scoped_ptr<drive::DriveUploaderInterface> drive_uploader) { | 204 scoped_ptr<drive::DriveUploaderInterface> drive_uploader) { |
| 204 return make_scoped_ptr(new APIUtil( | 205 return make_scoped_ptr(new APIUtil( |
| 205 temp_dir_path, | 206 temp_dir_path, |
| 206 GURL(kFakeServerBaseUrl), | 207 GURL(kFakeServerBaseUrl), |
| 207 GURL(kFakeDownloadServerBaseUrl), | 208 GURL(kFakeDownloadServerBaseUrl), |
| 208 drive_service.Pass(), | 209 drive_service.Pass(), |
| 209 drive_uploader.Pass())); | 210 drive_uploader.Pass(), |
| 211 kFakeAccountId)); |
| 210 } | 212 } |
| 211 | 213 |
| 212 APIUtil::APIUtil(const base::FilePath& temp_dir_path, | 214 APIUtil::APIUtil(const base::FilePath& temp_dir_path, |
| 213 const GURL& base_url, | 215 const GURL& base_url, |
| 214 const GURL& base_download_url, | 216 const GURL& base_download_url, |
| 215 scoped_ptr<drive::DriveServiceInterface> drive_service, | 217 scoped_ptr<drive::DriveServiceInterface> drive_service, |
| 216 scoped_ptr<drive::DriveUploaderInterface> drive_uploader) | 218 scoped_ptr<drive::DriveUploaderInterface> drive_uploader, |
| 219 const std::string& account_id) |
| 217 : wapi_url_generator_(base_url, base_download_url), | 220 : wapi_url_generator_(base_url, base_download_url), |
| 218 drive_api_url_generator_(base_url, base_download_url), | 221 drive_api_url_generator_(base_url, base_download_url), |
| 219 upload_next_key_(0), | 222 upload_next_key_(0), |
| 220 temp_dir_path_(temp_dir_path) { | 223 temp_dir_path_(temp_dir_path) { |
| 221 drive_service_ = drive_service.Pass(); | 224 drive_service_ = drive_service.Pass(); |
| 222 drive_service_->Initialize(); | 225 drive_service_->Initialize(account_id); |
| 223 drive_service_->AddObserver(this); | 226 drive_service_->AddObserver(this); |
| 224 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 227 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 225 | 228 |
| 226 drive_uploader_ = drive_uploader.Pass(); | 229 drive_uploader_ = drive_uploader.Pass(); |
| 227 } | 230 } |
| 228 | 231 |
| 229 APIUtil::~APIUtil() { | 232 APIUtil::~APIUtil() { |
| 230 DCHECK(CalledOnValidThread()); | 233 DCHECK(CalledOnValidThread()); |
| 231 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 234 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 232 drive_service_->RemoveObserver(this); | 235 drive_service_->RemoveObserver(this); |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 } | 1141 } |
| 1139 | 1142 |
| 1140 std::string APIUtil::GetRootResourceId() const { | 1143 std::string APIUtil::GetRootResourceId() const { |
| 1141 if (IsDriveAPIDisabled()) | 1144 if (IsDriveAPIDisabled()) |
| 1142 return drive_service_->GetRootResourceId(); | 1145 return drive_service_->GetRootResourceId(); |
| 1143 return root_resource_id_; | 1146 return root_resource_id_; |
| 1144 } | 1147 } |
| 1145 | 1148 |
| 1146 } // namespace drive_backend | 1149 } // namespace drive_backend |
| 1147 } // namespace sync_file_system | 1150 } // namespace sync_file_system |
| OLD | NEW |