OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_DOM_UI_MOST_VISITED_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_DOM_UI_MOST_VISITED_HANDLER_H_ |
6 #define CHROME_BROWSER_DOM_UI_MOST_VISITED_HANDLER_H_ | 6 #define CHROME_BROWSER_DOM_UI_MOST_VISITED_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "chrome/browser/cancelable_request.h" | 12 #include "chrome/browser/cancelable_request.h" |
13 #include "chrome/browser/dom_ui/dom_ui.h" | 13 #include "chrome/browser/dom_ui/dom_ui.h" |
14 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/common/notification_observer.h" | 15 #include "chrome/common/notification_observer.h" |
16 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
17 #include "googleurl/src/gurl.h" | |
18 | 17 |
19 class DictionaryValue; | 18 class DictionaryValue; |
| 19 class GURL; |
20 class ListValue; | 20 class ListValue; |
21 class PageUsageData; | 21 class PageUsageData; |
22 class PrefService; | 22 class PrefService; |
23 class Value; | 23 class Value; |
24 | 24 |
25 // The handler for Javascript messages related to the "most visited" view. | 25 // The handler for Javascript messages related to the "most visited" view. |
26 class MostVisitedHandler : public DOMMessageHandler, | 26 class MostVisitedHandler : public DOMMessageHandler, |
27 public NotificationObserver { | 27 public NotificationObserver { |
28 public: | 28 public: |
29 // This struct is used when getting the pre-populated pages in case the user | |
30 // hasn't filled up his most visited pages. | |
31 struct MostVisitedPage { | |
32 std::wstring title; | |
33 GURL url; | |
34 GURL thumbnail_url; | |
35 GURL favicon_url; | |
36 }; | |
37 | 29 |
38 MostVisitedHandler(); | 30 MostVisitedHandler(); |
39 virtual ~MostVisitedHandler() { } | 31 virtual ~MostVisitedHandler() { } |
40 | 32 |
41 // DOMMessageHandler override and implementation. | 33 // DOMMessageHandler override and implementation. |
42 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 34 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
43 virtual void RegisterMessages(); | 35 virtual void RegisterMessages(); |
44 | 36 |
45 // Callback for the "getMostVisited" message. | 37 // Callback for the "getMostVisited" message. |
46 void HandleGetMostVisited(const Value* value); | 38 void HandleGetMostVisited(const Value* value); |
(...skipping 21 matching lines...) Expand all Loading... |
68 const std::vector<GURL>& most_visited_urls() const { | 60 const std::vector<GURL>& most_visited_urls() const { |
69 return most_visited_urls_; | 61 return most_visited_urls_; |
70 } | 62 } |
71 | 63 |
72 static void RegisterUserPrefs(PrefService* prefs); | 64 static void RegisterUserPrefs(PrefService* prefs); |
73 | 65 |
74 // Returns Chrome Store URL with locale applied. | 66 // Returns Chrome Store URL with locale applied. |
75 static GURL GetChromeStoreURLWithLocale(); | 67 static GURL GetChromeStoreURLWithLocale(); |
76 | 68 |
77 private: | 69 private: |
| 70 struct MostVisitedPage; |
| 71 |
78 // Send a request to the HistoryService to get the most visited pages. | 72 // Send a request to the HistoryService to get the most visited pages. |
79 void StartQueryForMostVisited(); | 73 void StartQueryForMostVisited(); |
80 | 74 |
81 // Callback from the history system when the most visited list is available. | 75 // Callback from the history system when the most visited list is available. |
82 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, | 76 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, |
83 std::vector<PageUsageData*>* data); | 77 std::vector<PageUsageData*>* data); |
84 | 78 |
85 // Sets pages_value_ from a vector of URLs. | 79 // Sets pages_value_ from a vector of URLs. |
86 void SetPagesValue(std::vector<PageUsageData*>* data); | 80 void SetPagesValue(std::vector<PageUsageData*>* data); |
87 | 81 |
(...skipping 16 matching lines...) Expand all Loading... |
104 | 98 |
105 void AddPinnedURL(const MostVisitedPage& page, int index); | 99 void AddPinnedURL(const MostVisitedPage& page, int index); |
106 void RemovePinnedURL(const GURL& url); | 100 void RemovePinnedURL(const GURL& url); |
107 | 101 |
108 // Sends pages_value_ to the javascript side to and resets page_value_. | 102 // Sends pages_value_ to the javascript side to and resets page_value_. |
109 void SendPagesValue(); | 103 void SendPagesValue(); |
110 | 104 |
111 // Returns true if we should treat this as the first run of the new tab page. | 105 // Returns true if we should treat this as the first run of the new tab page. |
112 bool IsFirstRun(); | 106 bool IsFirstRun(); |
113 | 107 |
| 108 // Adds the fields in the page to the dictionary. |
| 109 static void SetMostVisistedPage( |
| 110 DictionaryValue* dict, |
| 111 const MostVisitedHandler::MostVisitedPage& page); |
| 112 |
114 static const std::vector<MostVisitedPage>& GetPrePopulatedPages(); | 113 static const std::vector<MostVisitedPage>& GetPrePopulatedPages(); |
115 | 114 |
116 static MostVisitedPage GetChromeStorePage(); | 115 static MostVisitedPage GetChromeStorePage(); |
117 | 116 |
118 // Whether we have any apps installed. | 117 // Whether we have any apps installed. |
119 bool HasApps() const; | 118 bool HasApps() const; |
120 | 119 |
121 NotificationRegistrar registrar_; | 120 NotificationRegistrar registrar_; |
122 | 121 |
123 // Our consumer for the history service. | 122 // Our consumer for the history service. |
(...skipping 20 matching lines...) Expand all Loading... |
144 // we get the first getMostVisited() call. | 143 // we get the first getMostVisited() call. |
145 bool got_first_most_visited_request_; | 144 bool got_first_most_visited_request_; |
146 | 145 |
147 // Keep the results of the db query here. | 146 // Keep the results of the db query here. |
148 scoped_ptr<ListValue> pages_value_; | 147 scoped_ptr<ListValue> pages_value_; |
149 | 148 |
150 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler); | 149 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler); |
151 }; | 150 }; |
152 | 151 |
153 #endif // CHROME_BROWSER_DOM_UI_MOST_VISITED_HANDLER_H_ | 152 #endif // CHROME_BROWSER_DOM_UI_MOST_VISITED_HANDLER_H_ |
OLD | NEW |