OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/util/extensions_activity_monitor.h" | 5 #include "chrome/browser/sync/util/extensions_activity_monitor.h" |
6 | 6 |
7 #include "base/task.h" | 7 #include "base/task.h" |
8 #include "chrome/browser/extensions/extension_bookmarks_module.h" | 8 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
| 9 #include "chrome/common/chrome_notification_types.h" |
9 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
10 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
11 #include "content/common/notification_service.h" | 12 #include "content/common/notification_service.h" |
12 | 13 |
13 namespace browser_sync { | 14 namespace browser_sync { |
14 | 15 |
15 namespace { | 16 namespace { |
16 // A helper task to register an ExtensionsActivityMonitor as an observer of | 17 // A helper task to register an ExtensionsActivityMonitor as an observer of |
17 // events on the UI thread (even though the monitor may live on another thread). | 18 // events on the UI thread (even though the monitor may live on another thread). |
18 // This liberates ExtensionsActivityMonitor from having to be ref counted. | 19 // This liberates ExtensionsActivityMonitor from having to be ref counted. |
19 class RegistrationTask : public Task { | 20 class RegistrationTask : public Task { |
20 public: | 21 public: |
21 RegistrationTask(ExtensionsActivityMonitor* monitor, | 22 RegistrationTask(ExtensionsActivityMonitor* monitor, |
22 NotificationRegistrar* registrar) | 23 NotificationRegistrar* registrar) |
23 : monitor_(monitor), registrar_(registrar) {} | 24 : monitor_(monitor), registrar_(registrar) {} |
24 virtual ~RegistrationTask() {} | 25 virtual ~RegistrationTask() {} |
25 | 26 |
26 virtual void Run() { | 27 virtual void Run() { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
28 | 29 |
29 // It would be nice if we could specify a Source for each specific function | 30 // It would be nice if we could specify a Source for each specific function |
30 // we wanted to observe, but the actual function objects are allocated on | 31 // we wanted to observe, but the actual function objects are allocated on |
31 // the fly so there is no reliable object to point to (same problem if we | 32 // the fly so there is no reliable object to point to (same problem if we |
32 // wanted to use the string name). Thus, we use all sources and filter in | 33 // wanted to use the string name). Thus, we use all sources and filter in |
33 // Observe. | 34 // Observe. |
34 registrar_->Add(monitor_, NotificationType::EXTENSION_BOOKMARKS_API_INVOKED, | 35 registrar_->Add(monitor_, |
| 36 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
35 NotificationService::AllSources()); | 37 NotificationService::AllSources()); |
36 } | 38 } |
37 | 39 |
38 private: | 40 private: |
39 ExtensionsActivityMonitor* monitor_; | 41 ExtensionsActivityMonitor* monitor_; |
40 NotificationRegistrar* registrar_; | 42 NotificationRegistrar* registrar_; |
41 DISALLOW_COPY_AND_ASSIGN(RegistrationTask); | 43 DISALLOW_COPY_AND_ASSIGN(RegistrationTask); |
42 }; | 44 }; |
43 } // namespace | 45 } // namespace |
44 | 46 |
(...skipping 26 matching lines...) Expand all Loading... |
71 } | 73 } |
72 | 74 |
73 void ExtensionsActivityMonitor::PutRecords(const Records& records) { | 75 void ExtensionsActivityMonitor::PutRecords(const Records& records) { |
74 base::AutoLock lock(records_lock_); | 76 base::AutoLock lock(records_lock_); |
75 for (Records::const_iterator i = records.begin(); i != records.end(); ++i) { | 77 for (Records::const_iterator i = records.begin(); i != records.end(); ++i) { |
76 records_[i->first].extension_id = i->second.extension_id; | 78 records_[i->first].extension_id = i->second.extension_id; |
77 records_[i->first].bookmark_write_count += i->second.bookmark_write_count; | 79 records_[i->first].bookmark_write_count += i->second.bookmark_write_count; |
78 } | 80 } |
79 } | 81 } |
80 | 82 |
81 void ExtensionsActivityMonitor::Observe(NotificationType type, | 83 void ExtensionsActivityMonitor::Observe(int type, |
82 const NotificationSource& source, | 84 const NotificationSource& source, |
83 const NotificationDetails& details) { | 85 const NotificationDetails& details) { |
84 base::AutoLock lock(records_lock_); | 86 base::AutoLock lock(records_lock_); |
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
86 const Extension* extension = Source<const Extension>(source).ptr(); | 88 const Extension* extension = Source<const Extension>(source).ptr(); |
87 const BookmarksFunction* f = Details<const BookmarksFunction>(details).ptr(); | 89 const BookmarksFunction* f = Details<const BookmarksFunction>(details).ptr(); |
88 if (f->name() == "bookmarks.update" || | 90 if (f->name() == "bookmarks.update" || |
89 f->name() == "bookmarks.move" || | 91 f->name() == "bookmarks.move" || |
90 f->name() == "bookmarks.create" || | 92 f->name() == "bookmarks.create" || |
91 f->name() == "bookmarks.removeTree" || | 93 f->name() == "bookmarks.removeTree" || |
92 f->name() == "bookmarks.remove") { | 94 f->name() == "bookmarks.remove") { |
93 Record& record = records_[extension->id()]; | 95 Record& record = records_[extension->id()]; |
94 record.extension_id = extension->id(); | 96 record.extension_id = extension->id(); |
95 record.bookmark_write_count++; | 97 record.bookmark_write_count++; |
96 } | 98 } |
97 } | 99 } |
98 | 100 |
99 } // namespace browser_sync | 101 } // namespace browser_sync |
OLD | NEW |