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