Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / glue / extensions_activity_monitor.cc
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.
4
5 #include "chrome/browser/sync/glue/extensions_activity_monitor.h"
6
7 #include "content/public/browser/browser_thread.h"
8 #include "sync/util/extensions_activity.h"
9
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"
15 #endif
16
17 using content::BrowserThread;
18
19 namespace browser_sync {
20
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
28   // Observe.
29 #if defined(ENABLE_EXTENSIONS)
30   registrar_.Add(this,
31                  extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED,
32                  content::NotificationService::AllSources());
33 #endif
34 }
35
36 ExtensionsActivityMonitor::~ExtensionsActivityMonitor() {
37   DCHECK_CURRENTLY_ON(BrowserThread::UI);
38 }
39
40 void ExtensionsActivityMonitor::Observe(
41     int type,
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());
57   }
58 #endif
59 }
60
61 const scoped_refptr<syncer::ExtensionsActivity>&
62 ExtensionsActivityMonitor::GetExtensionsActivity() {
63   return extensions_activity_;
64 }
65
66 }  // namespace browser_sync