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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_
6 #define CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_
10 #include "base/basictypes.h"
11 #include "components/keyed_service/core/keyed_service.h"
16 // 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
18 // error should be shown using this service. Examples of global errors are:
19 // - the previous session crashed for a given profile.
20 // - a sync error occurred
21 class GlobalErrorService
: public KeyedService
{
23 // Type used to represent the list of currently active errors.
24 typedef std::vector
<GlobalError
*> GlobalErrorList
;
26 // Constructs a GlobalErrorService object for the given profile. The profile
27 // maybe NULL for tests.
28 explicit GlobalErrorService(Profile
* profile
);
29 ~GlobalErrorService() override
;
31 // 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
33 // displayed once a browser window is opened. This class takes ownership of
35 void AddGlobalError(GlobalError
* error
);
37 // Hides the given error and removes it from the list of global errors. Caller
38 // then takes ownership of the error and is responsible for deleting it.
39 void RemoveGlobalError(GlobalError
* error
);
41 // Gets the error with the given command ID or NULL if no such error exists.
42 // This class maintains ownership of the returned error.
43 GlobalError
* GetGlobalErrorByMenuItemCommandID(int command_id
) const;
45 // Gets the highest severity error that has a wrench menu item.
46 // Returns NULL if no such error exists.
47 GlobalError
* GetHighestSeverityGlobalErrorWithWrenchMenuItem() const;
49 // Gets the first error that has a bubble view which hasn't been shown yet.
50 // Returns NULL if no such error exists.
51 GlobalError
* GetFirstGlobalErrorWithBubbleView() const;
54 const GlobalErrorList
& errors() { return errors_
; }
56 // 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
59 void NotifyErrorsChanged(GlobalError
* error
);
62 GlobalErrorList errors_
;
65 DISALLOW_COPY_AND_ASSIGN(GlobalErrorService
);
68 #endif // CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_H_