OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/glue/extensions_activity_monitor.h" | 5 #include "chrome/browser/sync/glue/extensions_activity_monitor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "content/public/browser/browser_thread.h" |
| 8 #include "sync/util/extensions_activity.h" |
| 9 |
| 10 #if defined(ENABLE_EXTENSIONS) |
8 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" | 12 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" |
10 #include "content/public/browser/browser_thread.h" | |
11 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
12 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
13 #include "sync/util/extensions_activity.h" | 15 #endif |
14 | 16 |
15 using content::BrowserThread; | 17 using content::BrowserThread; |
16 | 18 |
17 namespace browser_sync { | 19 namespace browser_sync { |
18 | 20 |
19 ExtensionsActivityMonitor::ExtensionsActivityMonitor() | 21 ExtensionsActivityMonitor::ExtensionsActivityMonitor() |
20 : extensions_activity_(new syncer::ExtensionsActivity()) { | 22 : extensions_activity_(new syncer::ExtensionsActivity()) { |
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 23 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
22 // It would be nice if we could specify a Source for each specific function | 24 // It would be nice if we could specify a Source for each specific function |
23 // we wanted to observe, but the actual function objects are allocated on | 25 // we wanted to observe, but the actual function objects are allocated on |
24 // the fly so there is no reliable object to point to (same problem if we | 26 // the fly so there is no reliable object to point to (same problem if we |
25 // wanted to use the string name). Thus, we use all sources and filter in | 27 // wanted to use the string name). Thus, we use all sources and filter in |
26 // Observe. | 28 // Observe. |
| 29 #if defined(ENABLE_EXTENSIONS) |
27 registrar_.Add(this, | 30 registrar_.Add(this, |
28 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | 31 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
29 content::NotificationService::AllSources()); | 32 content::NotificationService::AllSources()); |
| 33 #endif |
30 } | 34 } |
31 | 35 |
32 ExtensionsActivityMonitor::~ExtensionsActivityMonitor() { | 36 ExtensionsActivityMonitor::~ExtensionsActivityMonitor() { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
34 } | 38 } |
35 | 39 |
36 void ExtensionsActivityMonitor::Observe( | 40 void ExtensionsActivityMonitor::Observe( |
37 int type, | 41 int type, |
38 const content::NotificationSource& source, | 42 const content::NotificationSource& source, |
39 const content::NotificationDetails& details) { | 43 const content::NotificationDetails& details) { |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 #if defined(ENABLE_EXTENSIONS) |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 46 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, type); |
41 const extensions::Extension* extension = | 47 const extensions::Extension* extension = |
42 content::Source<const extensions::Extension>(source).ptr(); | 48 content::Source<const extensions::Extension>(source).ptr(); |
43 const extensions::BookmarksFunction* f = | 49 const extensions::BookmarksFunction* f = |
44 content::Details<const extensions::BookmarksFunction>(details).ptr(); | 50 content::Details<const extensions::BookmarksFunction>(details).ptr(); |
45 if (f->name() == "bookmarks.update" || | 51 if (f->name() == "bookmarks.update" || |
46 f->name() == "bookmarks.move" || | 52 f->name() == "bookmarks.move" || |
47 f->name() == "bookmarks.create" || | 53 f->name() == "bookmarks.create" || |
48 f->name() == "bookmarks.removeTree" || | 54 f->name() == "bookmarks.removeTree" || |
49 f->name() == "bookmarks.remove") { | 55 f->name() == "bookmarks.remove") { |
50 extensions_activity_->UpdateRecord(extension->id()); | 56 extensions_activity_->UpdateRecord(extension->id()); |
51 } | 57 } |
| 58 #endif |
52 } | 59 } |
53 | 60 |
54 const scoped_refptr<syncer::ExtensionsActivity>& | 61 const scoped_refptr<syncer::ExtensionsActivity>& |
55 ExtensionsActivityMonitor::GetExtensionsActivity() { | 62 ExtensionsActivityMonitor::GetExtensionsActivity() { |
56 return extensions_activity_; | 63 return extensions_activity_; |
57 } | 64 } |
58 | 65 |
59 } // namespace browser_sync | 66 } // namespace browser_sync |
OLD | NEW |