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