| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/media_galleries/gallery_watch_manager.h" | 5 #include "chrome/browser/media_galleries/gallery_watch_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 25 | 25 |
| 26 using content::BrowserContext; | 26 using content::BrowserContext; |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Don't send a notification more than once per 3 seconds (chosen arbitrarily). | 31 // Don't send a notification more than once per 3 seconds (chosen arbitrarily). |
| 32 const int kMinNotificiationDelayInSeconds = 3; | 32 const int kMinNotificationDelayInSeconds = 3; |
| 33 | 33 |
| 34 class ShutdownNotifierFactory | 34 class ShutdownNotifierFactory |
| 35 : public BrowserContextKeyedServiceShutdownNotifierFactory { | 35 : public BrowserContextKeyedServiceShutdownNotifierFactory { |
| 36 public: | 36 public: |
| 37 static ShutdownNotifierFactory* GetInstance() { | 37 static ShutdownNotifierFactory* GetInstance() { |
| 38 return base::Singleton<ShutdownNotifierFactory>::get(); | 38 return base::Singleton<ShutdownNotifierFactory>::get(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 friend struct base::DefaultSingletonTraits<ShutdownNotifierFactory>; | 42 friend struct base::DefaultSingletonTraits<ShutdownNotifierFactory>; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 observers_[profile]->OnGalleryWatchDropped(it->extension_id, | 409 observers_[profile]->OnGalleryWatchDropped(it->extension_id, |
| 410 it->gallery_id); | 410 it->gallery_id); |
| 411 } | 411 } |
| 412 | 412 |
| 413 return; | 413 return; |
| 414 } | 414 } |
| 415 | 415 |
| 416 base::TimeDelta time_since_last_notify = | 416 base::TimeDelta time_since_last_notify = |
| 417 base::Time::Now() - notification_info->second.last_notify_time; | 417 base::Time::Now() - notification_info->second.last_notify_time; |
| 418 if (time_since_last_notify < | 418 if (time_since_last_notify < |
| 419 base::TimeDelta::FromSeconds(kMinNotificiationDelayInSeconds)) { | 419 base::TimeDelta::FromSeconds(kMinNotificationDelayInSeconds)) { |
| 420 if (!notification_info->second.delayed_notification_pending) { | 420 if (!notification_info->second.delayed_notification_pending) { |
| 421 notification_info->second.delayed_notification_pending = true; | 421 notification_info->second.delayed_notification_pending = true; |
| 422 base::TimeDelta delay_to_next_valid_time = | 422 base::TimeDelta delay_to_next_valid_time = |
| 423 notification_info->second.last_notify_time + | 423 notification_info->second.last_notify_time + |
| 424 base::TimeDelta::FromSeconds(kMinNotificiationDelayInSeconds) - | 424 base::TimeDelta::FromSeconds(kMinNotificationDelayInSeconds) - |
| 425 base::Time::Now(); | 425 base::Time::Now(); |
| 426 BrowserThread::PostDelayedTask( | 426 BrowserThread::PostDelayedTask( |
| 427 BrowserThread::UI, | 427 BrowserThread::UI, |
| 428 FROM_HERE, | 428 FROM_HERE, |
| 429 base::Bind(&GalleryWatchManager::OnFilePathChanged, | 429 base::Bind(&GalleryWatchManager::OnFilePathChanged, |
| 430 weak_factory_.GetWeakPtr(), | 430 weak_factory_.GetWeakPtr(), |
| 431 path, | 431 path, |
| 432 error), | 432 error), |
| 433 delay_to_next_valid_time); | 433 delay_to_next_valid_time); |
| 434 } | 434 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 DeactivateFileWatch(owner, it->second); | 493 DeactivateFileWatch(owner, it->second); |
| 494 // Post increment moves iterator to next element while deleting current. | 494 // Post increment moves iterator to next element while deleting current. |
| 495 watches_.erase(it++); | 495 watches_.erase(it++); |
| 496 observers_[preferences->profile()]->OnGalleryWatchDropped( | 496 observers_[preferences->profile()]->OnGalleryWatchDropped( |
| 497 owner.extension_id, owner.gallery_id); | 497 owner.extension_id, owner.gallery_id); |
| 498 } else { | 498 } else { |
| 499 ++it; | 499 ++it; |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 } | 502 } |
| OLD | NEW |