OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/system_info_watcher.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace extensions { |
| 10 |
| 11 SystemInfoWatcher::SystemInfoWatcher() { |
| 12 } |
| 13 |
| 14 SystemInfoWatcher::~SystemInfoWatcher() { |
| 15 } |
| 16 |
| 17 // static |
| 18 void SystemInfoWatcher::InitializeForTesting(SystemInfoWatcher* watcher) { |
| 19 DCHECK(watcher); |
| 20 single_shared_watcher_.Get().reset(watcher); |
| 21 } |
| 22 |
| 23 void SystemInfoWatcher::AddObserver(Observer* observer) { |
| 24 DCHECK(observer); |
| 25 observers_.AddObserver(observer); |
| 26 } |
| 27 |
| 28 void SystemInfoWatcher::RemoveObserver(Observer* observer) { |
| 29 DCHECK(observer); |
| 30 observers_.RemoveObserver(observer); |
| 31 } |
| 32 |
| 33 bool SystemInfoWatcher::StartWatching(const std::string& event_name) { |
| 34 if (IsWatching(event_name)) |
| 35 return true; |
| 36 return PlatformStartWatching(event_name); |
| 37 } |
| 38 |
| 39 bool SystemInfoWatcher::StopWatching(const std::string& event_name) { |
| 40 bool success = true; |
| 41 if (IsWatching(event_name)) { |
| 42 success = PlatformStopWatching(event_name); |
| 43 watching_event_names_.erase(event_name); |
| 44 } |
| 45 return success; |
| 46 } |
| 47 |
| 48 bool SystemInfoWatcher::IsWatching(const std::string& event_name) { |
| 49 return watching_event_names_.find(event_name) != watching_event_names_.end(); |
| 50 } |
| 51 |
| 52 // The single shared instance initialization. |
| 53 base::LazyInstance<scoped_ptr<SystemInfoWatcher> > |
| 54 SystemInfoWatcher::single_shared_watcher_ = LAZY_INSTANCE_INITIALIZER; |
| 55 |
| 56 } // namespace extensions |
OLD | NEW |