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

Side by Side Diff: chrome/browser/instant/instant_service.h

Issue 12732005: Most visited thumbnails and favicons need id-based urls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase with Sreeram's MV clicks change Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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_INSTANT_INSTANT_SERVICE_H_ 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_
6 #define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ 6 #define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_
7 7
8 #include <map>
8 #include <set> 9 #include <set>
10 #include <string>
9 11
10 #include "base/basictypes.h" 12 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/profiles/profile_keyed_service.h" 15 #include "chrome/browser/profiles/profile_keyed_service.h"
14 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
16 18
19 class GURL;
17 class InstantIOContext; 20 class InstantIOContext;
18 class Profile; 21 class Profile;
19 22
23 namespace net {
24 class URLRequest;
25 }
26
20 // Tracks render process host IDs that are associated with Instant. 27 // Tracks render process host IDs that are associated with Instant.
21 class InstantService : public ProfileKeyedService, 28 class InstantService : public ProfileKeyedService,
22 public content::NotificationObserver { 29 public content::NotificationObserver {
23 public: 30 public:
24 explicit InstantService(Profile* profile); 31 explicit InstantService(Profile* profile);
25 virtual ~InstantService(); 32 virtual ~InstantService();
26 33
34 // A utility to translate an Instant path if it is of Most Visited item ID
35 // form. If path is a Most Visited item ID and we have a URL for it, then
36 // this URL is returned in string form. The |path| is a URL fragment
37 // corresponding to the path of url with the leading slash ("/") stripped.
38 // For example, chrome-search://favicon/72 would yield a |path| value of "72",
39 // and since 72 is a valid uint64 the path is translated to a valid url,
40 // "http://bingo.com/", say.
41 static const std::string MaybeTranslateInstantPathOnUI(
42 Profile* profile, const std::string& path);
43 static const std::string MaybeTranslateInstantPathOnIO(
44 const net::URLRequest* request, const std::string& path);
45 static bool IsInstantPath(const GURL& url);
46
27 // Add, remove, and query RenderProcessHost IDs that are associated with 47 // Add, remove, and query RenderProcessHost IDs that are associated with
28 // Instant processes. 48 // Instant processes.
29 void AddInstantProcess(int process_id); 49 void AddInstantProcess(int process_id);
30 bool IsInstantProcess(int process_id) const; 50 bool IsInstantProcess(int process_id) const;
31 51
32 #if defined(UNIT_TEST) 52 #if defined(UNIT_TEST)
33 int GetInstantProcessCount() const { 53 int GetInstantProcessCount() const {
34 return process_ids_.size(); 54 return process_ids_.size();
35 } 55 }
36 #endif 56 #endif
37 57
58 // If |url| is known the existing Most Visited item ID is returned. Otherwise
59 // a new Most Visited item ID is associated with the |url| and returned.
60 uint64 AddURL(const GURL& url);
61
62 // If there is a mapping for the |url|, sets |most_visited_item_id| and
63 // returns true.
64 bool GetMostVisitedItemIDForURL(const GURL& url,
65 uint64* most_visited_item_id);
66
67 // If there is a mapping for the |most_visited_item_id|, sets |url| and
68 // returns true.
69 bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url);
70
38 private: 71 private:
39 // Overridden from ProfileKeyedService: 72 // Overridden from ProfileKeyedService:
40 virtual void Shutdown() OVERRIDE; 73 virtual void Shutdown() OVERRIDE;
41 74
42 // Overridden from content::NotificationObserver: 75 // Overridden from content::NotificationObserver:
43 virtual void Observe(int type, 76 virtual void Observe(int type,
44 const content::NotificationSource& source, 77 const content::NotificationSource& source,
45 const content::NotificationDetails& details) OVERRIDE; 78 const content::NotificationDetails& details) OVERRIDE;
46 79
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
Evan Stade 2013/03/12 01:30:23 I would turn this into 2 functions, one which dele
dhollowa 2013/03/12 01:48:07 Done.
82 // deleted Most Visited item IDs.
83 void DeleteHistoryURLs(const std::vector<GURL>& deleted_urls,
84 bool all_history,
85 std::vector<uint64>* deleted_ids);
86
47 Profile* const profile_; 87 Profile* const profile_;
48 88
49 // The process ids associated with Instant processes. 89 // The process ids associated with Instant processes.
50 std::set<int> process_ids_; 90 std::set<int> process_ids_;
51 91
92 // A mapping of Most Visited IDs to URLs. Used to hide Most Visted and
Evan Stade 2013/03/12 01:30:23 nit: Visited
dhollowa 2013/03/12 01:48:07 Done.
93 // Favicon URLs from the Instant search provider.
94 uint64 last_most_visited_item_id_;
95 std::map<uint64, GURL> most_visited_item_id_to_url_map_;
96 std::map<GURL, uint64> url_to_most_visited_item_id_map_;
97
52 content::NotificationRegistrar registrar_; 98 content::NotificationRegistrar registrar_;
53 99
54 scoped_refptr<InstantIOContext> instant_io_context_; 100 scoped_refptr<InstantIOContext> instant_io_context_;
55 101
56 DISALLOW_COPY_AND_ASSIGN(InstantService); 102 DISALLOW_COPY_AND_ASSIGN(InstantService);
57 }; 103 };
58 104
59 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ 105 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698