Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_prompt_controller.h
blob20e82264f706b67234e852aaa2009c9322cdc449
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"
16 #include "url/gurl.h"
18 class Browser;
19 class PrefService;
21 namespace content {
22 class WebContents;
25 // BookmarkPromptController is a kind of singleton object held by
26 // BrowserProcessImpl, and controls showing bookmark prompt for frequently
27 // visited URLs.
28 class BookmarkPromptController : public chrome::BrowserListObserver,
29 public content::NotificationObserver,
30 public TabStripModelObserver {
31 public:
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
40 // prompt.
41 static const int kVisitCountForSessionTrigger;
43 // An instance of BookmarkPromptController is constructed only if bookmark
44 // feature enabled.
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();
62 private:
63 // TabStripModelObserver
64 virtual void ActiveTabChanged(content::WebContents* old_contents,
65 content::WebContents* new_contents,
66 int index,
67 int reason) OVERRIDE;
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,
83 bool success,
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|
91 // can be null.
92 void SetWebContents(content::WebContents* web_contents);
94 // Current active browser cache which we will display the prompt on it.
95 Browser* browser_;
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
104 // time.
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_