OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SEARCH_INSTANT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
6 #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 6 #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
16 #include "chrome/common/instant_restricted_id_cache.h" | |
16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 | 19 |
19 class GURL; | 20 class GURL; |
20 class InstantIOContext; | 21 class InstantIOContext; |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 class URLRequest; | 25 class URLRequest; |
25 } | 26 } |
(...skipping 22 matching lines...) Expand all Loading... | |
48 // Instant processes. | 49 // Instant processes. |
49 void AddInstantProcess(int process_id); | 50 void AddInstantProcess(int process_id); |
50 bool IsInstantProcess(int process_id) const; | 51 bool IsInstantProcess(int process_id) const; |
51 | 52 |
52 #if defined(UNIT_TEST) | 53 #if defined(UNIT_TEST) |
53 int GetInstantProcessCount() const { | 54 int GetInstantProcessCount() const { |
54 return process_ids_.size(); | 55 return process_ids_.size(); |
55 } | 56 } |
56 #endif | 57 #endif |
57 | 58 |
58 // If |url| is known the existing Most Visited item ID is returned. Otherwise | 59 ///// Most visited item API. |
sreeram
2013/03/19 21:36:17
Too many slashes.
Shishir
2013/03/19 22:20:20
Done.
| |
59 // a new Most Visited item ID is associated with the |url| and returned. | |
60 uint64 AddURL(const GURL& url); | |
61 | 60 |
62 // If there is a mapping for the |url|, sets |most_visited_item_id| and | 61 // Adds |items| to the |most_visited_item_cache_| assigning restricted IDs in |
63 // returns true. | 62 // the process. |
64 bool GetMostVisitedItemIDForURL(const GURL& url, | 63 void AddMostVisitedItems(const std::vector<InstantMostVisitedItem>& items); |
65 uint64* most_visited_item_id); | |
66 | 64 |
67 // If there is a mapping for the |most_visited_item_id|, sets |url| and | 65 // Returns the last added InstantMostVisitedItems. After the call to |
68 // returns true. | 66 // |AddMostVisitedItems|, the caller should call this to get the items with |
69 bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url); | 67 // the assigned IDs. |
68 void GetCurrentMostVisitedItems( | |
69 std::vector<InstantMostVisitedItemIDPair>* items) const; | |
70 | |
71 // If the |most_visited_item_id| is found in the cache, sets the |item| to it | |
72 // and returns true. | |
73 bool GetMostVisitedItemForID(InstantRestrictedID most_visited_item_id, | |
74 InstantMostVisitedItem* item) const; | |
70 | 75 |
71 private: | 76 private: |
72 // Overridden from ProfileKeyedService: | 77 // Overridden from ProfileKeyedService: |
73 virtual void Shutdown() OVERRIDE; | 78 virtual void Shutdown() OVERRIDE; |
74 | 79 |
75 // Overridden from content::NotificationObserver: | 80 // Overridden from content::NotificationObserver: |
76 virtual void Observe(int type, | 81 virtual void Observe(int type, |
77 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
78 const content::NotificationDetails& details) OVERRIDE; | 83 const content::NotificationDetails& details) OVERRIDE; |
79 | 84 |
80 // Removes entries of each url in |deleted_urls| from the ID maps. Or all | |
81 // IDs if |all_history| is true. |deleted_ids| is filled with the newly | |
82 // deleted Most Visited item IDs. | |
83 void DeleteHistoryURLs(const std::vector<GURL>& deleted_urls, | |
84 std::vector<uint64>* deleted_ids); | |
85 | |
86 Profile* const profile_; | 85 Profile* const profile_; |
87 | 86 |
88 // The process ids associated with Instant processes. | 87 // The process ids associated with Instant processes. |
89 std::set<int> process_ids_; | 88 std::set<int> process_ids_; |
90 | 89 |
91 // A mapping of Most Visited IDs to URLs. Used to hide Most Visited and | 90 // A cache of the InstantMostVisitedItems sent to the Instant Pages. |
92 // Favicon URLs from the Instant search provider. | 91 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_item_cache_; |
93 uint64 last_most_visited_item_id_; | |
94 std::map<uint64, GURL> most_visited_item_id_to_url_map_; | |
95 std::map<GURL, uint64> url_to_most_visited_item_id_map_; | |
96 | 92 |
97 content::NotificationRegistrar registrar_; | 93 content::NotificationRegistrar registrar_; |
98 | 94 |
99 scoped_refptr<InstantIOContext> instant_io_context_; | 95 scoped_refptr<InstantIOContext> instant_io_context_; |
100 | 96 |
101 DISALLOW_COPY_AND_ASSIGN(InstantService); | 97 DISALLOW_COPY_AND_ASSIGN(InstantService); |
102 }; | 98 }; |
103 | 99 |
104 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 100 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
OLD | NEW |