OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/global_error_service.h" | 5 #include "chrome/browser/ui/global_error_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/ui/global_error.h" | 10 #include "chrome/browser/ui/global_error.h" |
| 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "content/common/notification_service.h" |
11 | 13 |
12 GlobalErrorService::GlobalErrorService() { | 14 GlobalErrorService::GlobalErrorService(Profile* profile) : profile_(profile) { |
13 } | 15 } |
14 | 16 |
15 GlobalErrorService::~GlobalErrorService() { | 17 GlobalErrorService::~GlobalErrorService() { |
16 STLDeleteElements(&errors_); | 18 STLDeleteElements(&errors_); |
17 } | 19 } |
18 | 20 |
19 void GlobalErrorService::AddGlobalError(GlobalError* error) { | 21 void GlobalErrorService::AddGlobalError(GlobalError* error) { |
20 errors_.push_back(error); | 22 errors_.push_back(error); |
| 23 NotifyErrorsChanged(error); |
21 } | 24 } |
22 | 25 |
23 void GlobalErrorService::RemoveGlobalError(GlobalError* error) { | 26 void GlobalErrorService::RemoveGlobalError(GlobalError* error) { |
24 errors_.erase(std::find(errors_.begin(), errors_.end(), error)); | 27 errors_.erase(std::find(errors_.begin(), errors_.end(), error)); |
| 28 NotifyErrorsChanged(error); |
25 } | 29 } |
26 | 30 |
27 GlobalError* GlobalErrorService::GetGlobalErrorByMenuItemCommandID( | 31 GlobalError* GlobalErrorService::GetGlobalErrorByMenuItemCommandID( |
28 int command_id) const { | 32 int command_id) const { |
29 for (std::vector<GlobalError*>::const_iterator | 33 for (std::vector<GlobalError*>::const_iterator |
30 it = errors_.begin(); it != errors_.end(); ++it) { | 34 it = errors_.begin(); it != errors_.end(); ++it) { |
31 GlobalError* error = *it; | 35 GlobalError* error = *it; |
32 if (error->HasMenuItem() && command_id == error->MenuItemCommandID()) | 36 if (error->HasMenuItem() && command_id == error->MenuItemCommandID()) |
33 return error; | 37 return error; |
34 } | 38 } |
(...skipping 12 matching lines...) Expand all Loading... |
47 | 51 |
48 GlobalError* GlobalErrorService::GetFirstGlobalErrorWithBubbleView() const { | 52 GlobalError* GlobalErrorService::GetFirstGlobalErrorWithBubbleView() const { |
49 for (std::vector<GlobalError*>::const_iterator | 53 for (std::vector<GlobalError*>::const_iterator |
50 it = errors_.begin(); it != errors_.end(); ++it) { | 54 it = errors_.begin(); it != errors_.end(); ++it) { |
51 GlobalError* error = *it; | 55 GlobalError* error = *it; |
52 if (error->HasBubbleView() && !error->HasShownBubbleView()) | 56 if (error->HasBubbleView() && !error->HasShownBubbleView()) |
53 return error; | 57 return error; |
54 } | 58 } |
55 return NULL; | 59 return NULL; |
56 } | 60 } |
| 61 |
| 62 void GlobalErrorService::NotifyErrorsChanged(GlobalError* error) { |
| 63 NotificationService::current()->Notify( |
| 64 chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 65 Source<Profile>(profile_), |
| 66 Details<GlobalError>(error)); |
| 67 } |
OLD | NEW |