void FakeBluetoothInterface::NotifyAdapterPropertiesChanged( int num_properties, bt_property_t* properties) { FOR_EACH_OBSERVER( Observer, observers_, AdapterPropertiesCallback(BT_STATUS_SUCCESS, num_properties, properties)); }
// static void BrowserList::SetLastActive(Browser* browser) { RemoveBrowserFrom(browser, &last_active_browsers_); last_active_browsers_.push_back(browser); FOR_EACH_OBSERVER(Observer, observers_, OnBrowserSetLastActive(browser)); }
// static void FieldTrialList::NotifyFieldTrialGroupSelection( const std::string& name, const std::string& group_name) { if(!global_) { return; } DCHECK(global_); FOR_EACH_OBSERVER(Observer, global_->observer_list_, OnFieldTrialGroupFinalized(name, group_name)); }
TEST(ObserverListTest, Basic) { Observer a(1), b(2), c(3); EXPECT_EQ(1, a.num()); EXPECT_EQ(2, b.num()); EXPECT_EQ(3, c.num()); std::shared_ptr<base::ObserverList<Observer>> observers(new base::ObserverList<Observer>()); observers->AddObserver(&a); observers->AddObserver(&b); observers->AddObserver(&c); FOR_EACH_OBSERVER(Observer, observers, set_num(10)); EXPECT_EQ(10, a.num()); EXPECT_EQ(10, b.num()); EXPECT_EQ(10, c.num()); }
// static void BrowserList::RemoveBrowser(Browser* browser) { RemoveBrowserFrom(browser, &last_active_browsers_); // Closing all windows does not indicate quitting the application on the Mac, // however, many UI tests rely on this behavior so leave it be for now and // simply ignore the behavior on the Mac outside of unit tests. // TODO(andybons): Fix the UI tests to Do The Right Thing. bool closing_last_browser = (browsers_.size() == 1); //NotificationService::current()->Notify( // chrome::NOTIFICATION_BROWSER_CLOSED, // Source<Browser>(browser), Details<bool>(&closing_last_browser)); RemoveBrowserFrom(browser, &browsers_); // Do some basic checking to try to catch evil observers // that change the list from under us. size_t original_count = observers_.size(); FOR_EACH_OBSERVER(Observer, observers_, OnBrowserRemoved(browser)); DCHECK_EQ(original_count, observers_.size()) << "observer list modified during notification"; // If the last Browser object was destroyed, make sure we try to close any // remaining dependent windows too. if(browsers_.empty()) { //delete activity_observer; //activity_observer = NULL; } // If we're exiting, send out the APP_TERMINATING notification to allow other // modules to shut themselves down. if(browsers_.empty() && browser_shutdown::IsTryingToQuit()) { // Last browser has just closed, and this is a user-initiated quit or there // is no module keeping the app alive, so send out our notification. No need // to call ProfileManager::ShutdownSessionServices() as part of the // shutdown, because Browser::WindowClosing() already makes sure that the // SessionService is created and notified. //NotificationService::current()->Notify( // content::NOTIFICATION_APP_TERMINATING, // NotificationService::AllSources(), // NotificationService::NoDetails()); AllBrowsersClosedAndAppExiting(); } EndKeepAlive(); }
MessageLoop::~MessageLoop() { assert(this == current()); // Clean up any unprocessed tasks, but take care: deleting a task could // result in the addition of more tasks (e.g., via DeleteSoon). We set a // limit on the number of times we will allow a deleted task to generate more // tasks. Normally, we should only pass through this loop once or twice. If // we end up hitting the loop limit, then it is probably due to one task that // is being stubborn. Inspect the queues to see who is left. bool did_work; for (int i = 0; i < 100; ++i) { DeletePendingTasks(); ReloadWorkQueue(); // If we end up with empty queues, then break out of the loop. did_work = DeletePendingTasks(); if (!did_work) break; } FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, PreDestroyCurrentMessageLoop()); internal::LocalStorage<MessageLoop>::GetInstance()->Set(nullptr); }
// static void BrowserList::AddBrowser(Browser* browser) { DCHECK(browser); browsers_.push_back(browser); StartKeepAlive(); //if(!activity_observer) //{ // activity_observer = new BrowserActivityObserver; //} //NotificationService::current()->Notify( // chrome::NOTIFICATION_BROWSER_OPENED, // Source<Browser>(browser), // NotificationService::NoDetails()); // Send out notifications after add has occurred. Do some basic checking to // try to catch evil observers that change the list from under us. size_t original_count = observers_.size(); FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser)); DCHECK_EQ(original_count, observers_.size()) << "observer list modified during notification"; }
void FakeBluetoothInterface::NotifyAdapterStateChanged(bt_state_t state) { FOR_EACH_OBSERVER(Observer, observers_, AdapterStateChangedCallback(state)); }
void MessageLoop::PostPrecessTask() { FOR_EACH_OBSERVER(TaskObserver, task_observers_, PostPrecessTask()); }