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 "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" 14 15 using content::BrowserThread; 16 17 namespace browser_sync { 18 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()); 30 } 31 32 ExtensionsActivityMonitor::~ExtensionsActivityMonitor() { 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 34 } 35 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()); 51 } 52 } 53 54 const scoped_refptr<syncer::ExtensionsActivity>& 55 ExtensionsActivityMonitor::GetExtensionsActivity() { 56 return extensions_activity_; 57 } 58 59 } // namespace browser_sync 60