| 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/chrome_notification_types.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
| 12 #include "content/common/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 13 | 13 |
| 14 namespace browser_sync { | 14 namespace browser_sync { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 // A helper task to register an ExtensionsActivityMonitor as an observer of | 17 // A helper task to register an ExtensionsActivityMonitor as an observer of |
| 18 // 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). |
| 19 // This liberates ExtensionsActivityMonitor from having to be ref counted. | 19 // This liberates ExtensionsActivityMonitor from having to be ref counted. |
| 20 class RegistrationTask : public Task { | 20 class RegistrationTask : public Task { |
| 21 public: | 21 public: |
| 22 RegistrationTask(ExtensionsActivityMonitor* monitor, | 22 RegistrationTask(ExtensionsActivityMonitor* monitor, |
| 23 content::NotificationRegistrar* registrar) | 23 content::NotificationRegistrar* registrar) |
| 24 : monitor_(monitor), registrar_(registrar) {} | 24 : monitor_(monitor), registrar_(registrar) {} |
| 25 virtual ~RegistrationTask() {} | 25 virtual ~RegistrationTask() {} |
| 26 | 26 |
| 27 virtual void Run() { | 27 virtual void Run() { |
| 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 29 | 29 |
| 30 // 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 |
| 31 // 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 |
| 32 // 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 |
| 33 // 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 |
| 34 // Observe. | 34 // Observe. |
| 35 registrar_->Add(monitor_, | 35 registrar_->Add(monitor_, |
| 36 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | 36 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
| 37 NotificationService::AllSources()); | 37 content::NotificationService::AllSources()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 ExtensionsActivityMonitor* monitor_; | 41 ExtensionsActivityMonitor* monitor_; |
| 42 content::NotificationRegistrar* registrar_; | 42 content::NotificationRegistrar* registrar_; |
| 43 DISALLOW_COPY_AND_ASSIGN(RegistrationTask); | 43 DISALLOW_COPY_AND_ASSIGN(RegistrationTask); |
| 44 }; | 44 }; |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 ExtensionsActivityMonitor::ExtensionsActivityMonitor() { | 47 ExtensionsActivityMonitor::ExtensionsActivityMonitor() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 f->name() == "bookmarks.create" || | 94 f->name() == "bookmarks.create" || |
| 95 f->name() == "bookmarks.removeTree" || | 95 f->name() == "bookmarks.removeTree" || |
| 96 f->name() == "bookmarks.remove") { | 96 f->name() == "bookmarks.remove") { |
| 97 Record& record = records_[extension->id()]; | 97 Record& record = records_[extension->id()]; |
| 98 record.extension_id = extension->id(); | 98 record.extension_id = extension->id(); |
| 99 record.bookmark_write_count++; | 99 record.bookmark_write_count++; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace browser_sync | 103 } // namespace browser_sync |
| OLD | NEW |