Commit 722186b0 authored by Oscar Johansson's avatar Oscar Johansson Committed by Commit Bot

Remove "using" to avoid namespace conflict

When building using Jumbo namespace aliases with the same
name may end up in the same unit, causing a conflict at
compilation. This commit removes "using windows" and
"using tabs" and instead call the namespace by its full
name. This is done to increase the robustness of the code.

std::unique_ptr<T>() are removed because of presubmit check
errors.

Bug: 850484
Change-Id: I91f44728d4b54dd15213bac602176ca8736bb3cd
Reviewed-on: https://chromium-review.googlesource.com/1107633Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Commit-Queue: Oscar Johansson <oscarj@opera.com>
Cr-Commit-Position: refs/heads/master@{#569267}
parent 7560bdf2
......@@ -44,7 +44,6 @@
namespace extensions {
namespace tabs = api::tabs;
namespace windows = api::windows;
namespace {
......@@ -76,14 +75,14 @@ bool SortTabsByRecency(const sessions::SessionTab* t1,
return t1->timestamp > t2->timestamp;
}
tabs::Tab CreateTabModelHelper(
api::tabs::Tab CreateTabModelHelper(
const sessions::SerializedNavigationEntry& current_navigation,
const std::string& session_id,
int index,
bool pinned,
bool active,
const Extension* extension) {
tabs::Tab tab_struct;
api::tabs::Tab tab_struct;
const GURL& url = current_navigation.virtual_url();
std::string title = base::UTF16ToUTF8(current_navigation.title());
......@@ -105,12 +104,12 @@ tabs::Tab CreateTabModelHelper(
return tab_struct;
}
std::unique_ptr<windows::Window> CreateWindowModelHelper(
std::unique_ptr<std::vector<tabs::Tab>> tabs,
std::unique_ptr<api::windows::Window> CreateWindowModelHelper(
std::unique_ptr<std::vector<api::tabs::Tab>> tabs,
const std::string& session_id,
const windows::WindowType& type,
const windows::WindowState& state) {
std::unique_ptr<windows::Window> window_struct(new windows::Window);
const api::windows::WindowType& type,
const api::windows::WindowState& state) {
std::unique_ptr<api::windows::Window> window_struct(new api::windows::Window);
window_struct->tabs = std::move(tabs);
window_struct->session_id.reset(new std::string(session_id));
window_struct->incognito = false;
......@@ -123,8 +122,8 @@ std::unique_ptr<windows::Window> CreateWindowModelHelper(
std::unique_ptr<api::sessions::Session> CreateSessionModelHelper(
int last_modified,
std::unique_ptr<tabs::Tab> tab,
std::unique_ptr<windows::Window> window) {
std::unique_ptr<api::tabs::Tab> tab,
std::unique_ptr<api::windows::Window> window) {
std::unique_ptr<api::sessions::Session> session_struct(
new api::sessions::Session());
session_struct->last_modified = last_modified;
......@@ -143,7 +142,7 @@ bool is_window_entry(const sessions::TabRestoreService::Entry& entry) {
} // namespace
tabs::Tab SessionsGetRecentlyClosedFunction::CreateTabModel(
api::tabs::Tab SessionsGetRecentlyClosedFunction::CreateTabModel(
const sessions::TabRestoreService::Tab& tab,
bool active) {
return CreateTabModelHelper(tab.navigations[tab.current_navigation_index],
......@@ -152,29 +151,29 @@ tabs::Tab SessionsGetRecentlyClosedFunction::CreateTabModel(
extension());
}
std::unique_ptr<windows::Window>
std::unique_ptr<api::windows::Window>
SessionsGetRecentlyClosedFunction::CreateWindowModel(
const sessions::TabRestoreService::Window& window) {
DCHECK(!window.tabs.empty());
auto tabs = std::make_unique<std::vector<tabs::Tab>>();
auto tabs = std::make_unique<std::vector<api::tabs::Tab>>();
for (const auto& tab : window.tabs)
tabs->push_back(
CreateTabModel(*tab, tab->tabstrip_index == window.selected_tab_index));
return CreateWindowModelHelper(
std::move(tabs), base::IntToString(window.id.id()),
windows::WINDOW_TYPE_NORMAL, windows::WINDOW_STATE_NORMAL);
api::windows::WINDOW_TYPE_NORMAL, api::windows::WINDOW_STATE_NORMAL);
}
std::unique_ptr<api::sessions::Session>
SessionsGetRecentlyClosedFunction::CreateSessionModel(
const sessions::TabRestoreService::Entry& entry) {
std::unique_ptr<tabs::Tab> tab;
std::unique_ptr<windows::Window> window;
std::unique_ptr<api::tabs::Tab> tab;
std::unique_ptr<api::windows::Window> window;
switch (entry.type) {
case sessions::TabRestoreService::TAB:
tab.reset(new tabs::Tab(CreateTabModel(
tab.reset(new api::tabs::Tab(CreateTabModel(
static_cast<const sessions::TabRestoreService::Tab&>(entry), false)));
break;
case sessions::TabRestoreService::WINDOW:
......@@ -221,7 +220,7 @@ ExtensionFunction::ResponseAction SessionsGetRecentlyClosedFunction::Run() {
return RespondNow(ArgumentList(GetRecentlyClosed::Results::Create(result)));
}
tabs::Tab SessionsGetDevicesFunction::CreateTabModel(
api::tabs::Tab SessionsGetDevicesFunction::CreateTabModel(
const std::string& session_tag,
const sessions::SessionTab& tab,
int tab_index,
......@@ -232,7 +231,8 @@ tabs::Tab SessionsGetDevicesFunction::CreateTabModel(
tab.pinned, active, extension());
}
std::unique_ptr<windows::Window> SessionsGetDevicesFunction::CreateWindowModel(
std::unique_ptr<api::windows::Window>
SessionsGetDevicesFunction::CreateWindowModel(
const sessions::SessionWindow& window,
const std::string& session_tag) {
DCHECK(!window.tabs.empty());
......@@ -253,10 +253,11 @@ std::unique_ptr<windows::Window> SessionsGetDevicesFunction::CreateWindowModel(
tabs_in_window.push_back(tab);
}
if (tabs_in_window.empty())
return std::unique_ptr<windows::Window>();
return nullptr;
std::sort(tabs_in_window.begin(), tabs_in_window.end(), SortTabsByRecency);
std::unique_ptr<std::vector<tabs::Tab>> tabs(new std::vector<tabs::Tab>());
std::unique_ptr<std::vector<api::tabs::Tab>> tabs(
new std::vector<api::tabs::Tab>());
for (size_t i = 0; i < tabs_in_window.size(); ++i) {
tabs->push_back(CreateTabModel(session_tag, *tabs_in_window[i], i,
window.selected_tab_index == (int)i));
......@@ -265,29 +266,29 @@ std::unique_ptr<windows::Window> SessionsGetDevicesFunction::CreateWindowModel(
std::string session_id =
SessionId(session_tag, window.window_id.id()).ToString();
windows::WindowType type = windows::WINDOW_TYPE_NONE;
api::windows::WindowType type = api::windows::WINDOW_TYPE_NONE;
switch (window.type) {
case sessions::SessionWindow::TYPE_TABBED:
type = windows::WINDOW_TYPE_NORMAL;
type = api::windows::WINDOW_TYPE_NORMAL;
break;
case sessions::SessionWindow::TYPE_POPUP:
type = windows::WINDOW_TYPE_POPUP;
type = api::windows::WINDOW_TYPE_POPUP;
break;
}
windows::WindowState state = windows::WINDOW_STATE_NONE;
api::windows::WindowState state = api::windows::WINDOW_STATE_NONE;
switch (window.show_state) {
case ui::SHOW_STATE_NORMAL:
state = windows::WINDOW_STATE_NORMAL;
state = api::windows::WINDOW_STATE_NORMAL;
break;
case ui::SHOW_STATE_MINIMIZED:
state = windows::WINDOW_STATE_MINIMIZED;
state = api::windows::WINDOW_STATE_MINIMIZED;
break;
case ui::SHOW_STATE_MAXIMIZED:
state = windows::WINDOW_STATE_MAXIMIZED;
state = api::windows::WINDOW_STATE_MAXIMIZED;
break;
case ui::SHOW_STATE_FULLSCREEN:
state = windows::WINDOW_STATE_FULLSCREEN;
state = api::windows::WINDOW_STATE_FULLSCREEN;
break;
case ui::SHOW_STATE_DEFAULT:
case ui::SHOW_STATE_INACTIVE:
......@@ -295,7 +296,7 @@ std::unique_ptr<windows::Window> SessionsGetDevicesFunction::CreateWindowModel(
break;
}
std::unique_ptr<windows::Window> window_struct(
std::unique_ptr<api::windows::Window> window_struct(
CreateWindowModelHelper(std::move(tabs), session_id, type, state));
// TODO(dwankri): Dig deeper to resolve bounds not being optional, so closed
// windows in GetRecentlyClosed can have set values in Window helper.
......@@ -311,14 +312,15 @@ std::unique_ptr<api::sessions::Session>
SessionsGetDevicesFunction::CreateSessionModel(
const sessions::SessionWindow& window,
const std::string& session_tag) {
std::unique_ptr<windows::Window> window_model(
std::unique_ptr<api::windows::Window> window_model(
CreateWindowModel(window, session_tag));
// There is a chance that after pruning uninteresting tabs the window will be
// empty.
return !window_model ? std::unique_ptr<api::sessions::Session>()
: CreateSessionModelHelper(window.timestamp.ToTimeT(),
std::unique_ptr<tabs::Tab>(),
std::move(window_model));
return !window_model
? nullptr
: CreateSessionModelHelper(window.timestamp.ToTimeT(),
std::unique_ptr<api::tabs::Tab>(),
std::move(window_model));
}
api::sessions::Device SessionsGetDevicesFunction::CreateDeviceModel(
......@@ -383,11 +385,11 @@ ExtensionFunction::ResponseAction SessionsGetDevicesFunction::Run() {
ExtensionFunction::ResponseValue SessionsRestoreFunction::GetRestoredTabResult(
content::WebContents* contents) {
std::unique_ptr<tabs::Tab> tab(ExtensionTabUtil::CreateTabObject(
std::unique_ptr<api::tabs::Tab> tab(ExtensionTabUtil::CreateTabObject(
contents, ExtensionTabUtil::kScrubTab, extension()));
std::unique_ptr<api::sessions::Session> restored_session(
CreateSessionModelHelper(base::Time::Now().ToTimeT(), std::move(tab),
std::unique_ptr<windows::Window>()));
std::unique_ptr<api::windows::Window>()));
return ArgumentList(Restore::Results::Create(*restored_session));
}
......@@ -402,10 +404,10 @@ SessionsRestoreFunction::GetRestoredWindowResult(int window_id) {
std::unique_ptr<base::DictionaryValue> window_value(
ExtensionTabUtil::CreateWindowValueForExtension(
*browser, extension(), ExtensionTabUtil::kPopulateTabs));
std::unique_ptr<windows::Window> window(
windows::Window::FromValue(*window_value));
std::unique_ptr<api::windows::Window> window(
api::windows::Window::FromValue(*window_value));
return ArgumentList(Restore::Results::Create(*CreateSessionModelHelper(
base::Time::Now().ToTimeT(), std::unique_ptr<tabs::Tab>(),
base::Time::Now().ToTimeT(), std::unique_ptr<api::tabs::Tab>(),
std::move(window))));
}
......
......@@ -35,8 +35,6 @@ using zoom::ZoomController;
namespace extensions {
namespace tabs = api::tabs;
namespace {
bool WillDispatchTabUpdatedEvent(
......@@ -211,7 +209,7 @@ void TabsEventRouter::TabCreatedAt(WebContents* contents,
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
std::unique_ptr<base::ListValue> args(new base::ListValue);
auto event = std::make_unique<Event>(events::TABS_ON_CREATED,
tabs::OnCreated::kEventName,
api::tabs::OnCreated::kEventName,
std::move(args), profile);
event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED;
event->will_dispatch_callback =
......@@ -249,8 +247,9 @@ void TabsEventRouter::TabInsertedAt(TabStripModel* tab_strip_model,
args->Append(std::move(object_args));
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
DispatchEvent(profile, events::TABS_ON_ATTACHED,
api::tabs::OnAttached::kEventName, std::move(args),
EventRouter::USER_GESTURE_UNKNOWN);
}
void TabsEventRouter::TabDetachedAt(WebContents* contents,
......@@ -274,8 +273,9 @@ void TabsEventRouter::TabDetachedAt(WebContents* contents,
args->Append(std::move(object_args));
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
DispatchEvent(profile, events::TABS_ON_DETACHED,
api::tabs::OnDetached::kEventName, std::move(args),
EventRouter::USER_GESTURE_UNKNOWN);
}
void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model,
......@@ -295,8 +295,9 @@ void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model,
args->Append(std::move(object_args));
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
DispatchEvent(profile, events::TABS_ON_REMOVED,
api::tabs::OnRemoved::kEventName, std::move(args),
EventRouter::USER_GESTURE_UNKNOWN);
UnregisterForTabNotifications(contents);
}
......@@ -324,18 +325,19 @@ void TabsEventRouter::ActiveTabChanged(WebContents* old_contents,
? EventRouter::USER_GESTURE_ENABLED
: EventRouter::USER_GESTURE_NOT_ENABLED;
DispatchEvent(profile, events::TABS_ON_SELECTION_CHANGED,
tabs::OnSelectionChanged::kEventName, args->CreateDeepCopy(),
gesture);
api::tabs::OnSelectionChanged::kEventName,
args->CreateDeepCopy(), gesture);
DispatchEvent(profile, events::TABS_ON_ACTIVE_CHANGED,
tabs::OnActiveChanged::kEventName, std::move(args), gesture);
api::tabs::OnActiveChanged::kEventName, std::move(args),
gesture);
// The onActivated event takes one argument: {windowId, tabId}.
auto on_activated_args = std::make_unique<base::ListValue>();
object_args->Set(tabs_constants::kTabIdKey, std::make_unique<Value>(tab_id));
on_activated_args->Append(std::move(object_args));
DispatchEvent(profile, events::TABS_ON_ACTIVATED,
tabs::OnActivated::kEventName, std::move(on_activated_args),
gesture);
api::tabs::OnActivated::kEventName,
std::move(on_activated_args), gesture);
}
void TabsEventRouter::TabSelectionChanged(
......@@ -368,11 +370,11 @@ void TabsEventRouter::TabSelectionChanged(
// The onHighlighted event replaced onHighlightChanged.
Profile* profile = tab_strip_model->profile();
DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED,
tabs::OnHighlightChanged::kEventName,
api::tabs::OnHighlightChanged::kEventName,
std::unique_ptr<base::ListValue>(args->DeepCopy()),
EventRouter::USER_GESTURE_UNKNOWN);
DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED,
tabs::OnHighlighted::kEventName, std::move(args),
api::tabs::OnHighlighted::kEventName, std::move(args),
EventRouter::USER_GESTURE_UNKNOWN);
}
......@@ -394,7 +396,7 @@ void TabsEventRouter::TabMoved(WebContents* contents,
args->Append(std::move(object_args));
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_MOVED, tabs::OnMoved::kEventName,
DispatchEvent(profile, events::TABS_ON_MOVED, api::tabs::OnMoved::kEventName,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
}
......@@ -465,7 +467,7 @@ void TabsEventRouter::DispatchTabUpdatedEvent(
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
auto event = std::make_unique<Event>(events::TABS_ON_UPDATED,
tabs::OnUpdated::kEventName,
api::tabs::OnUpdated::kEventName,
std::move(args_base), profile);
event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED;
event->will_dispatch_callback =
......@@ -503,7 +505,7 @@ void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model,
args->AppendInteger(old_tab_id);
DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()),
events::TABS_ON_REPLACED, tabs::OnReplaced::kEventName,
events::TABS_ON_REPLACED, api::tabs::OnReplaced::kEventName,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
UnregisterForTabNotifications(old_contents);
......@@ -541,7 +543,7 @@ void TabsEventRouter::OnZoomChanged(
Profile* profile = Profile::FromBrowserContext(
data.web_contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_ZOOM_CHANGE,
tabs::OnZoomChange::kEventName,
api::tabs::OnZoomChange::kEventName,
api::tabs::OnZoomChange::Create(zoom_change_info),
EventRouter::USER_GESTURE_UNKNOWN);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment