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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/glue/extensions_activity_monitor.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "sync/util/extensions_activity.h"
10 #if defined(ENABLE_EXTENSIONS)
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h"
13 #include "content/public/browser/notification_service.h"
14 #include "extensions/common/extension.h"
17 using content::BrowserThread;
19 namespace browser_sync {
21 ExtensionsActivityMonitor::ExtensionsActivityMonitor()
22 : extensions_activity_(new syncer::ExtensionsActivity()) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI);
24 // 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 // 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
29 #if defined(ENABLE_EXTENSIONS)
31 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED,
32 content::NotificationService::AllSources());
36 ExtensionsActivityMonitor::~ExtensionsActivityMonitor() {
37 DCHECK_CURRENTLY_ON(BrowserThread::UI);
40 void ExtensionsActivityMonitor::Observe(
42 const content::NotificationSource& source,
43 const content::NotificationDetails& details) {
44 #if defined(ENABLE_EXTENSIONS)
45 DCHECK_CURRENTLY_ON(BrowserThread::UI);
46 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, type);
47 const extensions::Extension* extension =
48 content::Source<const extensions::Extension>(source).ptr();
49 const extensions::BookmarksFunction* f =
50 content::Details<const extensions::BookmarksFunction>(details).ptr();
51 if (f->name() == "bookmarks.update" ||
52 f->name() == "bookmarks.move" ||
53 f->name() == "bookmarks.create" ||
54 f->name() == "bookmarks.removeTree" ||
55 f->name() == "bookmarks.remove") {
56 extensions_activity_->UpdateRecord(extension->id());
61 const scoped_refptr<syncer::ExtensionsActivity>&
62 ExtensionsActivityMonitor::GetExtensionsActivity() {
63 return extensions_activity_;
66 } // namespace browser_sync