This source file includes following definitions.
- weak_factory_
- IgnoreBrowserClosing
- ShowInternal
- Observe
#include "chrome/browser/ui/extensions/extension_installed_bubble.h"
#include <string>
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "extensions/common/extension.h"
using content::Details;
using extensions::Extension;
namespace {
const int kAnimationWaitMs = 50;
const int kAnimationWaitRetries = 10;
}
ExtensionInstalledBubble::ExtensionInstalledBubble(Delegate* delegate,
const Extension* extension,
Browser *browser,
const SkBitmap& icon)
: delegate_(delegate),
extension_(extension),
browser_(browser),
icon_(icon),
animation_wait_retries_(0),
weak_factory_(this) {
if (!extensions::OmniboxInfo::GetKeyword(extension).empty())
type_ = OMNIBOX_KEYWORD;
else if (extensions::ActionInfo::GetBrowserActionInfo(extension))
type_ = BROWSER_ACTION;
else if (extensions::ActionInfo::GetPageActionInfo(extension) &&
extensions::ActionInfo::IsVerboseInstallMessage(extension))
type_ = PAGE_ACTION;
else
type_ = GENERIC;
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
content::Source<Profile>(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING,
content::Source<Browser>(browser));
}
ExtensionInstalledBubble::~ExtensionInstalledBubble() {}
void ExtensionInstalledBubble::IgnoreBrowserClosing() {
registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING,
content::Source<Browser>(browser_));
}
void ExtensionInstalledBubble::ShowInternal() {
if (delegate_->MaybeShowNow())
return;
if (animation_wait_retries_++ < kAnimationWaitRetries) {
base::MessageLoopForUI::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&ExtensionInstalledBubble::ShowInternal,
weak_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kAnimationWaitMs));
}
}
void ExtensionInstalledBubble::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_LOADED: {
const Extension* extension = Details<const Extension>(details).ptr();
if (extension == extension_) {
animation_wait_retries_ = 0;
base::MessageLoopForUI::current()->PostTask(
FROM_HERE,
base::Bind(&ExtensionInstalledBubble::ShowInternal,
weak_factory_.GetWeakPtr()));
}
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const Extension* extension =
Details<extensions::UnloadedExtensionInfo>(details)->extension;
if (extension == extension_) {
weak_factory_.InvalidateWeakPtrs();
extension_ = NULL;
}
break;
}
case chrome::NOTIFICATION_BROWSER_CLOSING:
delete delegate_;
break;
default:
NOTREACHED() << "Received unexpected notification";
}
}