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

Side by Side Diff: chrome/browser/extensions/mock_system_info_watcher.cc

Issue 10836341: Add the basic code skeleton for system info event router (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add mock implementation for onAdded and onRemoved events Created 8 years, 4 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
OLDNEW
(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/mock_system_info_watcher.h"
6
7 #include "chrome/browser/extensions/event_names.h"
8
9 namespace extensions {
10
11 namespace {
12
13 const int kDefaultInterval = 200; // default interval is 200ms.
14 const int kAvailableCapacityBase = 10000;
15 const int kChangeStep = 10;
16
17 }
18
19 MockSystemInfoWatcher::MockSystemInfoWatcher() {
20 }
21
22 MockSystemInfoWatcher::~MockSystemInfoWatcher() {
23 }
24
25 bool MockSystemInfoWatcher::PlatformStartWatching(
26 const std::string& event_name) {
27 // If the |event_name| event is already watched.
28 if (IsWatching(event_name))
29 return true;
30
31 if (event_name.compare(
32 event_names::kOnStorageAvailableCapacityChanged) == 0) {
33 // Start the timer to emulate storage.onChanged event.
34 timer_.Start(FROM_HERE,
35 base::TimeDelta::FromMilliseconds(kDefaultInterval),
36 this, &MockSystemInfoWatcher::OnTimeoutEvent);
37 }
38 return true;
39 }
40
41 bool MockSystemInfoWatcher::PlatformStopWatching(
42 const std::string& event_name) {
43 if (!IsWatching(event_name))
44 return false;
45
46 if (event_name.compare(
47 event_names::kOnStorageAvailableCapacityChanged) == 0) {
48 timer_.Stop();
49 }
50 return true;
51 }
52
53 void MockSystemInfoWatcher::OnTimeoutEvent() {
54 static int count = 0;
55
56 FOR_EACH_OBSERVER(Observer, observers_,
57 OnStorageDeviceAvailableCapacityChanged("/dev/sda1",
58 kAvailableCapacityBase - kChangeStep*count));
59
60 FOR_EACH_OBSERVER(Observer, observers_,
61 OnStorageDeviceAdded("/dev/sda2", "removable", 4096, 2048));
62
63 FOR_EACH_OBSERVER(Observer, observers_,
64 OnStorageDeviceRemoved("/dev/sda2"));
65
66 ++count;
67 }
68
69 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698