Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_ |
| 6 #define CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_ | 6 #define CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <memory> | |
| 8 #include <vector> | 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "components/keyed_service/core/keyed_service.h" | 13 #include "components/keyed_service/core/keyed_service.h" |
| 12 | 14 |
| 13 class GlobalError; | 15 class GlobalError; |
| 14 class Profile; | 16 class Profile; |
| 15 | 17 |
| 16 // This service manages a list of errors that are meant to be shown globally. | 18 // This service manages a list of errors that are meant to be shown globally. |
| 17 // If an error applies to an entire profile and not just to a tab then the | 19 // If an error applies to an entire profile and not just to a tab then the |
| 18 // error should be shown using this service. Examples of global errors are: | 20 // error should be shown using this service. Examples of global errors are: |
| 19 // - the previous session crashed for a given profile. | 21 // - the previous session crashed for a given profile. |
| 20 // - a sync error occurred | 22 // - a sync error occurred |
| 21 class GlobalErrorService : public KeyedService { | 23 class GlobalErrorService : public KeyedService { |
| 22 public: | 24 public: |
| 23 // Type used to represent the list of currently active errors. | 25 // Type used to represent the list of currently active errors. |
| 24 typedef std::vector<GlobalError*> GlobalErrorList; | 26 using GlobalErrorList = std::vector<GlobalError*>; |
| 25 | 27 |
| 26 // Constructs a GlobalErrorService object for the given profile. The profile | 28 // Constructs a GlobalErrorService object for the given profile. The profile |
| 27 // maybe NULL for tests. | 29 // maybe NULL for tests. |
| 28 explicit GlobalErrorService(Profile* profile); | 30 explicit GlobalErrorService(Profile* profile); |
| 29 ~GlobalErrorService() override; | 31 ~GlobalErrorService() override; |
| 30 | 32 |
| 31 // Adds the given error to the list of global errors and displays it on | 33 // Adds the given error to the list of global errors and displays it on |
| 32 // browswer windows. If no browser windows are open then the error is | 34 // browser windows. If no browser windows are open then the error is |
| 33 // displayed once a browser window is opened. This class takes ownership of | 35 // displayed once a browser window is opened. |
| 34 // the error. | 36 // |
| 35 void AddGlobalError(GlobalError* error); | 37 // The error can be added as an "owned" error, in which case the |
| 38 // GlobalErrorService takes ownership, or as an "unowned" error in which case | |
| 39 // the error's lifetime must exceed that of the GlobalErrorService. | |
| 40 void AddOwnedGlobalError(std::unique_ptr<GlobalError> error); | |
| 41 void AddUnownedGlobalError(GlobalError* error); | |
|
Nico
2016/12/12 22:32:50
Can we make this the default version (and call it
Avi (use Gerrit)
2016/12/13 03:06:19
Done.
| |
| 36 | 42 |
| 37 // Hides the given error and removes it from the list of global errors. Caller | 43 // Hides the given error and removes it from the list of global errors. If it |
| 38 // then takes ownership of the error and is responsible for deleting it. | 44 // was added as an owned error, ownership is returned to the caller; if it was |
| 39 void RemoveGlobalError(GlobalError* error); | 45 // added as an unowned error then the GlobalErrorService will not delete it. |
| 46 std::unique_ptr<GlobalError> RemoveOwnedGlobalError(GlobalError* error); | |
| 47 void RemoveUnownedGlobalError(GlobalError* error); | |
| 40 | 48 |
| 41 // Gets the error with the given command ID or NULL if no such error exists. | 49 // Gets the error with the given command ID or NULL if no such error exists. |
| 42 // This class maintains ownership of the returned error. | 50 // This class maintains ownership of the returned error. |
| 43 GlobalError* GetGlobalErrorByMenuItemCommandID(int command_id) const; | 51 GlobalError* GetGlobalErrorByMenuItemCommandID(int command_id) const; |
| 44 | 52 |
| 45 // Gets the highest severity error that has a app menu item. | 53 // Gets the highest severity error that has a app menu item. |
| 46 // Returns NULL if no such error exists. | 54 // Returns NULL if no such error exists. |
| 47 GlobalError* GetHighestSeverityGlobalErrorWithAppMenuItem() const; | 55 GlobalError* GetHighestSeverityGlobalErrorWithAppMenuItem() const; |
| 48 | 56 |
| 49 // Gets the first error that has a bubble view which hasn't been shown yet. | 57 // Gets the first error that has a bubble view which hasn't been shown yet. |
| 50 // Returns NULL if no such error exists. | 58 // Returns NULL if no such error exists. |
| 51 GlobalError* GetFirstGlobalErrorWithBubbleView() const; | 59 GlobalError* GetFirstGlobalErrorWithBubbleView() const; |
| 52 | 60 |
| 53 // Gets all errors. | 61 // Gets all errors. |
| 54 const GlobalErrorList& errors() { return errors_; } | 62 const GlobalErrorList& errors() { return all_errors_; } |
| 55 | 63 |
| 56 // Post a notification that a global error has changed and that the error UI | 64 // Post a notification that a global error has changed and that the error UI |
| 57 // should update it self. Pass NULL for the given error to mean all error UIs | 65 // should update it self. Pass NULL for the given error to mean all error UIs |
| 58 // should update. | 66 // should update. |
| 59 void NotifyErrorsChanged(GlobalError* error); | 67 void NotifyErrorsChanged(GlobalError* error); |
| 60 | 68 |
| 61 private: | 69 private: |
| 62 GlobalErrorList errors_; | 70 GlobalErrorList all_errors_; |
| 71 std::map<GlobalError*, std::unique_ptr<GlobalError>> owned_errors_; | |
| 63 Profile* profile_; | 72 Profile* profile_; |
| 64 | 73 |
| 65 DISALLOW_COPY_AND_ASSIGN(GlobalErrorService); | 74 DISALLOW_COPY_AND_ASSIGN(GlobalErrorService); |
| 66 }; | 75 }; |
| 67 | 76 |
| 68 #endif // CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_ | 77 #endif // CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_ |
| OLD | NEW |