1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_PROMPT_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_PROMPT_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/common/cancelable_request.h"
11 #include "chrome/browser/history/history_types.h"
12 #include "chrome/browser/ui/browser_list_observer.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
25 // BookmarkPromptController is a kind of singleton object held by
26 // BrowserProcessImpl, and controls showing bookmark prompt for frequently
28 class BookmarkPromptController
: public chrome::BrowserListObserver
,
29 public content::NotificationObserver
,
30 public TabStripModelObserver
{
32 // When impression count is greater than |kMaxPromptImpressionCount|, we
33 // don't display bookmark prompt anymore.
34 static const int kMaxPromptImpressionCount
;
36 // When user visited the URL 10 times, we show the bookmark prompt.
37 static const int kVisitCountForPermanentTrigger
;
39 // When user visited the URL 3 times last 24 hours, we show the bookmark
41 static const int kVisitCountForSessionTrigger
;
43 // An instance of BookmarkPromptController is constructed only if bookmark
45 BookmarkPromptController();
46 virtual ~BookmarkPromptController();
48 // Invoked when bookmark is added for |url| by clicking star icon in
49 // |browser|. Note: Clicking bookmark menu item in action box is also
50 // considered as clicking star icon.
51 static void AddedBookmark(Browser
* browser
, const GURL
& url
);
53 // Invoked when bookmark prompt is closing.
54 static void ClosingBookmarkPrompt();
56 // Disable bookmark prompt feature in a profile in |prefs|.
57 static void DisableBookmarkPrompt(PrefService
* prefs
);
59 // True if bookmark prompt feature is enabled, otherwise false.
60 static bool IsEnabled();
63 // TabStripModelObserver
64 virtual void ActiveTabChanged(content::WebContents
* old_contents
,
65 content::WebContents
* new_contents
,
69 void AddedBookmarkInternal(Browser
* browser
, const GURL
& url
);
70 void ClosingBookmarkPromptInternal();
72 // content::NotificationObserver:
73 virtual void Observe(int type
,
74 const content::NotificationSource
& source
,
75 const content::NotificationDetails
& details
) OVERRIDE
;
77 // chrome::BrowserListObserver
78 virtual void OnBrowserRemoved(Browser
* browser
) OVERRIDE
;
79 virtual void OnBrowserSetLastActive(Browser
* browser
) OVERRIDE
;
81 // Callback for the HistoryService::QueryURL
82 void OnDidQueryURL(CancelableRequestProvider::Handle handle
,
84 const history::URLRow
* url_row
,
85 history::VisitVector
* visits
);
87 // Set current active browser cache to |browser|. |browser| can be null.
88 void SetBrowser(Browser
* browser
);
90 // Set current active WebContents cache from |web_contents|. |web_contents|
92 void SetWebContents(content::WebContents
* web_contents
);
94 // Current active browser cache which we will display the prompt on it.
97 // Current active WebContents cache which we will display the prompt for it.
98 content::WebContents
* web_contents_
;
100 // Remember last URL for recording metrics.
101 GURL last_prompted_url_
;
103 // Last prompted time is used for measuring duration of prompt displaying
105 base::Time last_prompted_time_
;
107 // Start time of HistoryService::QueryURL.
108 base::Time query_url_start_time_
;
110 CancelableRequestConsumer query_url_consumer_
;
111 content::NotificationRegistrar registrar_
;
113 DISALLOW_COPY_AND_ASSIGN(BookmarkPromptController
);
116 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_PROMPT_CONTROLLER_H_