Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / glue / extensions_activity_monitor.cc
blob57687180bffe9438b6740ee3c8468c384637d003
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 "base/bind.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #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"
12 #include "extensions/common/extension.h"
13 #include "sync/util/extensions_activity.h"
15 using content::BrowserThread;
17 namespace browser_sync {
19 ExtensionsActivityMonitor::ExtensionsActivityMonitor()
20 : extensions_activity_(new syncer::ExtensionsActivity()) {
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
22 // 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
24 // 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
26 // Observe.
27 registrar_.Add(this,
28 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED,
29 content::NotificationService::AllSources());
32 ExtensionsActivityMonitor::~ExtensionsActivityMonitor() {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36 void ExtensionsActivityMonitor::Observe(
37 int type,
38 const content::NotificationSource& source,
39 const content::NotificationDetails& details) {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 const extensions::Extension* extension =
42 content::Source<const extensions::Extension>(source).ptr();
43 const extensions::BookmarksFunction* f =
44 content::Details<const extensions::BookmarksFunction>(details).ptr();
45 if (f->name() == "bookmarks.update" ||
46 f->name() == "bookmarks.move" ||
47 f->name() == "bookmarks.create" ||
48 f->name() == "bookmarks.removeTree" ||
49 f->name() == "bookmarks.remove") {
50 extensions_activity_->UpdateRecord(extension->id());
54 const scoped_refptr<syncer::ExtensionsActivity>&
55 ExtensionsActivityMonitor::GetExtensionsActivity() {
56 return extensions_activity_;
59 } // namespace browser_sync