diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 03:22:50 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 03:22:50 +0000 |
commit | e4e15dca9f700cf5f0e9ff708622ff0cebe94100 (patch) | |
tree | 34c1e4ffc83ea2144a1b36477c8845ce7bb3b79b /chrome/browser/instant/instant_preview_controller.cc | |
parent | b35c81cc0bd12bc4182105b40f8e2702ab684ea8 (diff) | |
download | chromium_src-e4e15dca9f700cf5f0e9ff708622ff0cebe94100.zip chromium_src-e4e15dca9f700cf5f0e9ff708622ff0cebe94100.tar.gz chromium_src-e4e15dca9f700cf5f0e9ff708622ff0cebe94100.tar.bz2 |
Refactor Instant to separate out preview control
Separates out Show/Hide logic into a separate |InstantPreviewController|
class. This class follows an observer pattern, observing the |InstantModel|
changes. The model is held by the |InstantController|.
The goal with this is to pave the way for future changes that will expand the
complexity of the "view" logic, especially in the area of coordinating the
animations used with --enable-instant-extended-api features.
BUG=142785
TEST=No functional change. Refactoring only.
R=sreeram@chromium.org, jered@chromium.org, samarth@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11144004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162633 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant/instant_preview_controller.cc')
-rw-r--r-- | chrome/browser/instant/instant_preview_controller.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/chrome/browser/instant/instant_preview_controller.cc b/chrome/browser/instant/instant_preview_controller.cc new file mode 100644 index 0000000..3283742d --- /dev/null +++ b/chrome/browser/instant/instant_preview_controller.cc @@ -0,0 +1,39 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/instant/instant_preview_controller.h" + +#include "chrome/browser/instant/instant_model.h" +#include "chrome/browser/instant/instant_controller.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_instant_controller.h" +#include "chrome/common/chrome_notification_types.h" +#include "content/public/browser/notification_service.h" + +InstantPreviewController::InstantPreviewController(Browser* browser) + : browser_(browser) { + registrar_.Add(this, chrome::NOTIFICATION_BROWSER_INSTANT_RESET, + content::NotificationService::AllSources()); + ResetInstant(); +} + +InstantPreviewController::~InstantPreviewController() { + InstantController* instant = browser_->instant_controller()->instant(); + if (instant) + instant->model()->RemoveObserver(this); +} + +void InstantPreviewController::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + DCHECK_EQ(chrome::NOTIFICATION_BROWSER_INSTANT_RESET, type); + ResetInstant(); +} + +void InstantPreviewController::ResetInstant() { + InstantController* instant = browser_->instant_controller()->instant(); + if (instant && !instant->model()->HasObserver(this)) + instant->model()->AddObserver(this); +} |