| 
									
										
										
										
											2016-05-27 08:51:02 +09:00
										 |  |  | // Copyright (c) 2016 GitHub, Inc.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef ATOM_BROWSER_RENDER_PROCESS_PREFERENCES_H_
 | 
					
						
							|  |  |  | #define ATOM_BROWSER_RENDER_PROCESS_PREFERENCES_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <memory>
 | 
					
						
							|  |  |  | #include <unordered_map>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "base/callback.h"
 | 
					
						
							|  |  |  | #include "base/values.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/notification_observer.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/notification_registrar.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace content { | 
					
						
							|  |  |  | class RenderProcessHost; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace atom { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Sets user preferences for render processes.
 | 
					
						
							|  |  |  | class RenderProcessPreferences : public content::NotificationObserver { | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   using Predicate = base::Callback<bool(content::RenderProcessHost*)>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // The |predicate| is used to determine whether to set preferences for a
 | 
					
						
							|  |  |  |   // render process.
 | 
					
						
							|  |  |  |   explicit RenderProcessPreferences(const Predicate& predicate); | 
					
						
							| 
									
										
										
										
											2018-04-17 16:03:51 -07:00
										 |  |  |   ~RenderProcessPreferences() override; | 
					
						
							| 
									
										
										
										
											2016-05-27 08:51:02 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   int AddEntry(const base::DictionaryValue& entry); | 
					
						
							|  |  |  |   void RemoveEntry(int id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   // content::NotificationObserver:
 | 
					
						
							|  |  |  |   void Observe(int type, | 
					
						
							|  |  |  |                const content::NotificationSource& source, | 
					
						
							|  |  |  |                const content::NotificationDetails& details) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void UpdateCache(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Manages our notification registrations.
 | 
					
						
							|  |  |  |   content::NotificationRegistrar registrar_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Predicate predicate_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   int next_id_ = 0; | 
					
						
							| 
									
										
										
										
											2016-05-27 08:51:02 +09:00
										 |  |  |   std::unordered_map<int, std::unique_ptr<base::DictionaryValue>> entries_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // We need to convert the |entries_| to ListValue for multiple times, this
 | 
					
						
							|  |  |  |   // caches is only updated when we are sending messages.
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   bool cache_needs_update_ = true; | 
					
						
							| 
									
										
										
										
											2016-05-27 08:51:02 +09:00
										 |  |  |   base::ListValue cached_entries_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DISALLOW_COPY_AND_ASSIGN(RenderProcessPreferences); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace atom
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // ATOM_BROWSER_RENDER_PROCESS_PREFERENCES_H_
 |