Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchObservable.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 package org.chromium.chrome.browser.contextualsearch;
6
7 import org.chromium.base.ObserverList;
8 import org.chromium.chrome.browser.ChromeActivity;
9 import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection;
10 import org.chromium.content.browser.ContentViewCore;
11
12 import java.net.URL;
13
14 import javax.annotation.Nullable;
15
16
17 /**
18 * Provides observers for the Contextual Search Manager.
19 */
20 public class ContextualSearchObservable {
21
22 protected final ContextualSearchPolicy mPolicy;
23
24 private final ObserverList<ContextualSearchObserver> mObservers =
25 new ObserverList<ContextualSearchObserver>();
26
27
28 ContextualSearchObservable(ChromeActivity activity) {
29 mPolicy = ContextualSearchPolicy.getInstance(activity);
30 }
31
32 /**
33 * @param observer The observer to notify when the user performs a contextua l search.
34 */
35 public void addObserver(ContextualSearchObserver observer) {
36 mObservers.addObserver(observer);
37 }
38
39 /**
40 * @param observer The observer to no longer notify when the user performs a contextual search.
41 */
42 public void removeObserver(ContextualSearchObserver observer) {
43 mObservers.removeObserver(observer);
44 }
45
46 /**
47 * Notifies all Contextual Search observers that a search has occurred.
48 * @param selectionContext The selection and context that triggered the sear ch.
49 * @param baseContentViewUrl The {@link ContentViewCore} of the base page.
50 */
51 protected void notifyShowContextualSearch(GSAContextDisplaySelection selecti onContext,
52 @Nullable URL baseContentViewUrl) {
53 if (!mPolicy.canSendSurroundings(baseContentViewUrl)) selectionContext = null;
54
55 for (ContextualSearchObserver observer : mObservers) {
56 observer.onShowContextualSearch(selectionContext);
57 }
58 }
59
60 /**
61 * Notifies all Contextual Search observers that a search ended and is no lo nger in effect.
62 */
63 protected void notifyHideContextualSearch() {
64 for (ContextualSearchObserver observer : mObservers) {
65 observer.onHideContextualSearch();
66 }
67 }
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698