Chromium Code Reviews| 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_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 |
| 20 // Tracks render process host IDs that are associated with Instant. | 23 // Tracks render process host IDs that are associated with Instant. |
| 21 class InstantService : public ProfileKeyedService, | 24 class InstantService : public ProfileKeyedService, |
| 22 public content::NotificationObserver { | 25 public content::NotificationObserver { |
| 23 public: | 26 public: |
| 24 explicit InstantService(Profile* profile); | 27 explicit InstantService(Profile* profile); |
| 25 virtual ~InstantService(); | 28 virtual ~InstantService(); |
| 26 | 29 |
| 30 // A utility to translate an Instant path if it is of restricted ID | |
| 31 // form. If path is a restricted ID and we have a URL for it, then | |
|
palmer
2013/03/11 20:42:31
What kind of path? What is in these strings?
dhollowa
2013/03/11 23:27:59
Done.
| |
| 32 // this URL is returned in string form. | |
| 33 static const std::string MaybeTranslateInstantPath(Profile* profile, | |
|
palmer
2013/03/11 20:42:31
Can |profile| be const?
dhollowa
2013/03/11 23:27:59
No, very difficult as mentioned.
| |
| 34 const std::string& path); | |
| 35 static bool IsInstantPath(const GURL& url); | |
| 36 | |
| 27 // Add, remove, and query RenderProcessHost IDs that are associated with | 37 // Add, remove, and query RenderProcessHost IDs that are associated with |
| 28 // Instant processes. | 38 // Instant processes. |
| 29 void AddInstantProcess(int process_id); | 39 void AddInstantProcess(int process_id); |
| 30 bool IsInstantProcess(int process_id) const; | 40 bool IsInstantProcess(int process_id) const; |
| 31 | 41 |
| 32 #if defined(UNIT_TEST) | 42 #if defined(UNIT_TEST) |
| 33 int GetInstantProcessCount() const { | 43 int GetInstantProcessCount() const { |
| 34 return process_ids_.size(); | 44 return process_ids_.size(); |
| 35 } | 45 } |
| 36 #endif | 46 #endif |
| 37 | 47 |
| 48 // If |url| is known the exiting restricted ID is returned. Otherwise a new | |
|
Evan Stade
2013/03/11 21:01:27
sp: existing
dhollowa
2013/03/11 23:27:59
Done.
| |
| 49 // restricted ID is associated with the |url| and returned. | |
| 50 uint64 AddURL(const GURL& url); | |
| 51 | |
| 52 // Returns true if the |url| is known, and |restricted_id| is set. | |
|
Evan Stade
2013/03/11 19:47:08
this comment format doesn't make sense to me. What
dhollowa
2013/03/11 20:05:23
Done. And below. (Thanks for the better wording.
| |
| 53 // Returns false otherwise. | |
| 54 bool GetRestrictedIDForURL(const GURL& url, uint64 *restricted_id); | |
|
Evan Stade
2013/03/11 19:47:08
asterisk always on left
dhollowa
2013/03/11 20:05:23
Done.
| |
| 55 | |
| 56 // Returns true if the |restricted_id| is known, and |url| is set. | |
| 57 // Returns false otherwise. | |
| 58 bool GetURLForRestrictedId(uint64 restricted_id, GURL* url); | |
| 59 | |
| 38 private: | 60 private: |
| 39 // Overridden from ProfileKeyedService: | 61 // Overridden from ProfileKeyedService: |
| 40 virtual void Shutdown() OVERRIDE; | 62 virtual void Shutdown() OVERRIDE; |
| 41 | 63 |
| 42 // Overridden from content::NotificationObserver: | 64 // Overridden from content::NotificationObserver: |
| 43 virtual void Observe(int type, | 65 virtual void Observe(int type, |
| 44 const content::NotificationSource& source, | 66 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) OVERRIDE; | 67 const content::NotificationDetails& details) OVERRIDE; |
| 46 | 68 |
| 47 Profile* const profile_; | 69 Profile* const profile_; |
| 48 | 70 |
| 49 // The process ids associated with Instant processes. | 71 // The process ids associated with Instant processes. |
| 50 std::set<int> process_ids_; | 72 std::set<int> process_ids_; |
| 51 | 73 |
| 74 // A mapping of restricted IDs to URLs. Used to hide Most Visted and Favicon | |
| 75 // URLs from the Instant search provider. | |
| 76 uint64 last_url_id_; | |
| 77 std::map<uint64, GURL> id_to_url_map_; | |
|
Evan Stade
2013/03/11 19:47:08
what kind of ID is this?
dhollowa
2013/03/11 20:05:23
I'm not quite sure what you're asking here. It is
Evan Stade
2013/03/11 21:01:27
I don't know what a restricted ID is. By looking a
dhollowa
2013/03/11 23:27:59
I've changed to most_visited_item_id to make thing
| |
| 78 std::map<GURL, uint64> url_to_id_map_; | |
| 79 | |
| 52 content::NotificationRegistrar registrar_; | 80 content::NotificationRegistrar registrar_; |
| 53 | 81 |
| 54 scoped_refptr<InstantIOContext> instant_io_context_; | 82 scoped_refptr<InstantIOContext> instant_io_context_; |
| 55 | 83 |
| 56 DISALLOW_COPY_AND_ASSIGN(InstantService); | 84 DISALLOW_COPY_AND_ASSIGN(InstantService); |
| 57 }; | 85 }; |
| 58 | 86 |
| 59 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ | 87 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
| OLD | NEW |