Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/chromeos/drive/drive_system_service.cc

Issue 13976019: Reland of https://codereview.chromium.org/13891016/. This includes the fix for the Segfault on Chro… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final rebase before dcommit attempt Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromeos/drive/drive_system_service.h" 5 #include "chrome/browser/chromeos/drive/drive_system_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/drive/download_handler.h" 11 #include "chrome/browser/chromeos/drive/download_handler.h"
12 #include "chrome/browser/chromeos/drive/drive_cache.h" 12 #include "chrome/browser/chromeos/drive/drive_cache.h"
13 #include "chrome/browser/chromeos/drive/drive_file_system.h" 13 #include "chrome/browser/chromeos/drive/drive_file_system.h"
14 #include "chrome/browser/chromeos/drive/drive_prefetcher.h" 14 #include "chrome/browser/chromeos/drive/drive_prefetcher.h"
15 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" 15 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h"
16 #include "chrome/browser/chromeos/drive/file_system_proxy.h" 16 #include "chrome/browser/chromeos/drive/file_system_proxy.h"
17 #include "chrome/browser/chromeos/drive/file_system_util.h" 17 #include "chrome/browser/chromeos/drive/file_system_util.h"
18 #include "chrome/browser/chromeos/drive/file_write_helper.h" 18 #include "chrome/browser/chromeos/drive/file_write_helper.h"
19 #include "chrome/browser/chromeos/drive/logging.h" 19 #include "chrome/browser/chromeos/drive/logging.h"
20 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h" 20 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h"
21 #include "chrome/browser/chromeos/drive/sync_client.h" 21 #include "chrome/browser/chromeos/drive/sync_client.h"
22 #include "chrome/browser/download/download_service.h" 22 #include "chrome/browser/download/download_service.h"
23 #include "chrome/browser/download/download_service_factory.h" 23 #include "chrome/browser/download/download_service_factory.h"
24 #include "chrome/browser/download/download_util.h" 24 #include "chrome/browser/download/download_util.h"
25 #include "chrome/browser/google_apis/auth_service.h" 25 #include "chrome/browser/google_apis/auth_service.h"
26 #include "chrome/browser/google_apis/drive_api_service.h" 26 #include "chrome/browser/google_apis/drive_api_service.h"
27 #include "chrome/browser/google_apis/drive_api_util.h" 27 #include "chrome/browser/google_apis/drive_api_util.h"
28 #include "chrome/browser/google_apis/drive_notification_manager.h"
29 #include "chrome/browser/google_apis/drive_notification_manager_factory.h"
28 #include "chrome/browser/google_apis/gdata_wapi_service.h" 30 #include "chrome/browser/google_apis/gdata_wapi_service.h"
29 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" 31 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
30 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/profiles/profile_dependency_manager.h" 33 #include "chrome/browser/profiles/profile_dependency_manager.h"
32 #include "chrome/browser/sync/profile_sync_service.h"
33 #include "chrome/browser/sync/profile_sync_service_factory.h" 34 #include "chrome/browser/sync/profile_sync_service_factory.h"
34 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/chrome_version_info.h" 36 #include "chrome/common/chrome_version_info.h"
36 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
37 #include "content/public/browser/browser_context.h" 38 #include "content/public/browser/browser_context.h"
38 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/storage_partition.h" 40 #include "content/public/browser/storage_partition.h"
40 #include "google/cacheinvalidation/types.pb.h" 41 #include "google/cacheinvalidation/types.pb.h"
41 #include "webkit/fileapi/external_mount_points.h" 42 #include "webkit/fileapi/external_mount_points.h"
42 #include "webkit/user_agent/user_agent_util.h" 43 #include "webkit/user_agent/user_agent_util.h"
43 44
44 using content::BrowserContext; 45 using content::BrowserContext;
45 using content::BrowserThread; 46 using content::BrowserThread;
46 47
47 namespace drive { 48 namespace drive {
48 namespace { 49 namespace {
49 50
50 // The sync invalidation object ID for Google Drive. 51 static const size_t kEventLogHistorySize = 100;
51 const char kDriveInvalidationObjectId[] = "CHANGELOG";
52 52
53 // Returns true if Drive is enabled for the given Profile. 53 // Returns true if Drive is enabled for the given Profile.
54 bool IsDriveEnabledForProfile(Profile* profile) { 54 bool IsDriveEnabledForProfile(Profile* profile) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 56
57 if (!google_apis::AuthService::CanAuthenticate(profile)) 57 if (!google_apis::AuthService::CanAuthenticate(profile))
58 return false; 58 return false;
59 59
60 // Disable Drive if preference is set. This can happen with commandline flag 60 // Disable Drive if preference is set. This can happen with commandline flag
61 // --disable-gdata or enterprise policy, or probably with user settings too 61 // --disable-gdata or enterprise policy, or probably with user settings too
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 } // namespace 98 } // namespace
99 99
100 DriveSystemService::DriveSystemService( 100 DriveSystemService::DriveSystemService(
101 Profile* profile, 101 Profile* profile,
102 google_apis::DriveServiceInterface* test_drive_service, 102 google_apis::DriveServiceInterface* test_drive_service,
103 const base::FilePath& test_cache_root, 103 const base::FilePath& test_cache_root,
104 DriveFileSystemInterface* test_file_system) 104 DriveFileSystemInterface* test_file_system)
105 : profile_(profile), 105 : profile_(profile),
106 drive_disabled_(false), 106 drive_disabled_(false),
107 push_notification_registered_(false),
108 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 107 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); 109 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
111 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( 110 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
112 blocking_pool->GetSequenceToken()); 111 blocking_pool->GetSequenceToken());
113 112
114 if (test_drive_service) { 113 if (test_drive_service) {
115 drive_service_.reset(test_drive_service); 114 drive_service_.reset(test_drive_service);
116 } else if (google_apis::util::IsDriveV2ApiEnabled()) { 115 } else if (google_apis::util::IsDriveV2ApiEnabled()) {
117 drive_service_.reset(new google_apis::DriveAPIService( 116 drive_service_.reset(new google_apis::DriveAPIService(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 drive_service_->Initialize(profile_); 164 drive_service_->Initialize(profile_);
166 file_system_->Initialize(); 165 file_system_->Initialize();
167 cache_->RequestInitialize( 166 cache_->RequestInitialize(
168 base::Bind(&DriveSystemService::InitializeAfterCacheInitialized, 167 base::Bind(&DriveSystemService::InitializeAfterCacheInitialized,
169 weak_ptr_factory_.GetWeakPtr())); 168 weak_ptr_factory_.GetWeakPtr()));
170 } 169 }
171 170
172 void DriveSystemService::Shutdown() { 171 void DriveSystemService::Shutdown() {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
174 173
175 ProfileSyncService* profile_sync_service = 174 google_apis::DriveNotificationManager* drive_notification_manager =
176 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; 175 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_);
177 if (profile_sync_service && push_notification_registered_) { 176 if (drive_notification_manager)
178 // TODO(kochi): Once DriveSystemService gets started / stopped at runtime, 177 drive_notification_manager->RemoveObserver(this);
179 // this ID needs to be unregistered *before* the handler is unregistered
180 // as ID persists across browser restarts.
181 if (!IsDriveEnabledForProfile(profile_)) {
182 profile_sync_service->UpdateRegisteredInvalidationIds(
183 this, syncer::ObjectIdSet());
184 }
185 profile_sync_service->UnregisterInvalidationHandler(this);
186 push_notification_registered_ = false;
187 }
188 178
189 RemoveDriveMountPoint(); 179 RemoveDriveMountPoint();
190 } 180 }
191 181
192 void DriveSystemService::AddObserver(DriveSystemServiceObserver* observer) { 182 void DriveSystemService::AddObserver(DriveSystemServiceObserver* observer) {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 observers_.AddObserver(observer); 184 observers_.AddObserver(observer);
195 } 185 }
196 186
197 void DriveSystemService::RemoveObserver(DriveSystemServiceObserver* observer) { 187 void DriveSystemService::RemoveObserver(DriveSystemServiceObserver* observer) {
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 observers_.RemoveObserver(observer); 189 observers_.RemoveObserver(observer);
200 } 190 }
201 191
192 void DriveSystemService::OnNotificationReceived() {
193 file_system_->CheckForUpdates();
194 }
195
202 bool DriveSystemService::IsDriveEnabled() { 196 bool DriveSystemService::IsDriveEnabled() {
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 198
205 if (!IsDriveEnabledForProfile(profile_)) 199 if (!IsDriveEnabledForProfile(profile_))
206 return false; 200 return false;
207 201
208 // Drive may be disabled for cache initialization failure, etc. 202 // Drive may be disabled for cache initialization failure, etc.
209 if (drive_disabled_) 203 if (drive_disabled_)
210 return false; 204 return false;
211 205
212 return true; 206 return true;
213 } 207 }
214 208
215 void DriveSystemService::OnInvalidatorStateChange(
216 syncer::InvalidatorState state) {
217 DVLOG(1) << "InvalidatorState changed to " << state;
218 }
219
220 void DriveSystemService::OnIncomingInvalidation(
221 const syncer::ObjectIdInvalidationMap& invalidation_map) {
222 DCHECK_EQ(1U, invalidation_map.size());
223 const invalidation::ObjectId object_id(
224 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
225 kDriveInvalidationObjectId);
226 DCHECK_EQ(1U, invalidation_map.count(object_id));
227
228 file_system_->CheckForUpdates();
229 }
230
231 void DriveSystemService::ClearCacheAndRemountFileSystem( 209 void DriveSystemService::ClearCacheAndRemountFileSystem(
232 const base::Callback<void(bool)>& callback) { 210 const base::Callback<void(bool)>& callback) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234 DCHECK(!callback.is_null()); 212 DCHECK(!callback.is_null());
235 213
236 RemoveDriveMountPoint(); 214 RemoveDriveMountPoint();
237 cache_->ClearAll(base::Bind( 215 cache_->ClearAll(base::Bind(
238 &DriveSystemService::ReinitializeResourceMetadataAfterClearCache, 216 &DriveSystemService::ReinitializeResourceMetadataAfterClearCache,
239 weak_ptr_factory_.GetWeakPtr(), 217 weak_ptr_factory_.GetWeakPtr(),
240 callback)); 218 callback));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
277 255
278 RemoveDriveMountPoint(); 256 RemoveDriveMountPoint();
279 file_system_->Reload(); 257 file_system_->Reload();
280 258
281 // Reload() is asynchronous. But we can add back the mount point right away 259 // Reload() is asynchronous. But we can add back the mount point right away
282 // because every operation waits until loading is complete. 260 // because every operation waits until loading is complete.
283 AddDriveMountPoint(); 261 AddDriveMountPoint();
284 } 262 }
285 263
286 bool DriveSystemService::PushNotificationEnabled() {
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
288 DCHECK(profile_);
289
290 ProfileSyncService* profile_sync_service =
291 ProfileSyncServiceFactory::GetForProfile(profile_);
292 if (!profile_sync_service)
293 return false;
294
295 return (profile_sync_service->GetInvalidatorState() ==
296 syncer::INVALIDATIONS_ENABLED);
297 }
298
299 void DriveSystemService::AddDriveMountPoint() { 264 void DriveSystemService::AddDriveMountPoint() {
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
301 DCHECK(!file_system_proxy_.get()); 266 DCHECK(!file_system_proxy_.get());
302 267
303 const base::FilePath drive_mount_point = util::GetDriveMountPointPath(); 268 const base::FilePath drive_mount_point = util::GetDriveMountPointPath();
304 fileapi::ExternalMountPoints* mount_points = 269 fileapi::ExternalMountPoints* mount_points =
305 BrowserContext::GetMountPoints(profile_); 270 BrowserContext::GetMountPoints(profile_);
306 DCHECK(mount_points); 271 DCHECK(mount_points);
307 272
308 file_system_proxy_ = new FileSystemProxy(file_system_.get()); 273 file_system_proxy_ = new FileSystemProxy(file_system_.get());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 333 }
369 334
370 content::DownloadManager* download_manager = 335 content::DownloadManager* download_manager =
371 g_browser_process->download_status_updater() ? 336 g_browser_process->download_status_updater() ?
372 BrowserContext::GetDownloadManager(profile_) : NULL; 337 BrowserContext::GetDownloadManager(profile_) : NULL;
373 download_handler_->Initialize( 338 download_handler_->Initialize(
374 download_manager, 339 download_manager,
375 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); 340 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP_DOWNLOADS));
376 341
377 // Register for Google Drive invalidation notifications. 342 // Register for Google Drive invalidation notifications.
378 ProfileSyncService* profile_sync_service = 343 google_apis::DriveNotificationManager* drive_notification_manager =
379 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; 344 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_);
380 if (profile_sync_service) { 345 if (drive_notification_manager)
381 DCHECK(!push_notification_registered_); 346 drive_notification_manager->AddObserver(this);
382 profile_sync_service->RegisterInvalidationHandler(this);
383 syncer::ObjectIdSet ids;
384 ids.insert(invalidation::ObjectId(
385 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
386 kDriveInvalidationObjectId));
387 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids);
388 push_notification_registered_ = true;
389 }
390 347
391 AddDriveMountPoint(); 348 AddDriveMountPoint();
392 } 349 }
393 350
394 void DriveSystemService::DisableDrive() { 351 void DriveSystemService::DisableDrive() {
395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
396 353
397 drive_disabled_ = true; 354 drive_disabled_ = true;
398 // Change the download directory to the default value if the download 355 // Change the download directory to the default value if the download
399 // destination is set to under Drive mount point. 356 // destination is set to under Drive mount point.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 405
449 // static 406 // static
450 void DriveSystemServiceFactory::SetFactoryForTest( 407 void DriveSystemServiceFactory::SetFactoryForTest(
451 const FactoryCallback& factory_for_test) { 408 const FactoryCallback& factory_for_test) {
452 GetInstance()->factory_for_test_ = factory_for_test; 409 GetInstance()->factory_for_test_ = factory_for_test;
453 } 410 }
454 411
455 DriveSystemServiceFactory::DriveSystemServiceFactory() 412 DriveSystemServiceFactory::DriveSystemServiceFactory()
456 : ProfileKeyedServiceFactory("DriveSystemService", 413 : ProfileKeyedServiceFactory("DriveSystemService",
457 ProfileDependencyManager::GetInstance()) { 414 ProfileDependencyManager::GetInstance()) {
458 DependsOn(ProfileSyncServiceFactory::GetInstance()); 415 DependsOn(google_apis::DriveNotificationManagerFactory::GetInstance());
459 DependsOn(DownloadServiceFactory::GetInstance()); 416 DependsOn(DownloadServiceFactory::GetInstance());
460 } 417 }
461 418
462 DriveSystemServiceFactory::~DriveSystemServiceFactory() { 419 DriveSystemServiceFactory::~DriveSystemServiceFactory() {
463 } 420 }
464 421
465 ProfileKeyedService* DriveSystemServiceFactory::BuildServiceInstanceFor( 422 ProfileKeyedService* DriveSystemServiceFactory::BuildServiceInstanceFor(
466 Profile* profile) const { 423 Profile* profile) const {
467 DriveSystemService* service = NULL; 424 DriveSystemService* service = NULL;
468 if (factory_for_test_.is_null()) 425 if (factory_for_test_.is_null())
469 service = new DriveSystemService(profile, NULL, base::FilePath(), NULL); 426 service = new DriveSystemService(profile, NULL, base::FilePath(), NULL);
470 else 427 else
471 service = factory_for_test_.Run(profile); 428 service = factory_for_test_.Run(profile);
472 429
473 service->Initialize(); 430 service->Initialize();
474 return service; 431 return service;
475 } 432 }
476 433
477 } // namespace drive 434 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_system_service.h ('k') | chrome/browser/google_apis/drive_notification_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698