Don't use anonymous namespace in header file.

Anonymous namespace should be forbidden in header files even for the
forward declarations:

* As declarations defined in anonymous namespace are internal linkage, each
translation unit which includes this header will get unique copy, which
wastes space.
* It is easy to violate C++ ODR rule.

Consider the following "foo.h":

```cpp
namespace { class Foo; }
class Bar {
  public:
    Foo* getFoo();
    Foo* foo;
}
```

If the 'foo.h' is included in multiple `.cc` files, the compiler will
put `Foo` into a different anonymous namespace in each `.cc`, which
means there are different definitions of `Foo` in the program (a
violation of the ODR).
This commit is contained in:
Haojian Wu 2017-03-31 21:27:06 +02:00
parent bd5c53c2f7
commit ee1f3acf7b
2 changed files with 5 additions and 11 deletions

View file

@ -178,7 +178,7 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) {
views::Widget::InitParams params; views::Widget::InitParams params;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.delegate = GetDevToolsWindowDelegate(); params.delegate = devtools_window_delegate_;
params.bounds = inspectable_web_contents()->GetDevToolsBounds(); params.bounds = inspectable_web_contents()->GetDevToolsBounds();
#if defined(USE_X11) #if defined(USE_X11)
@ -203,7 +203,8 @@ void InspectableWebContentsViewViews::SetContentsResizingStrategy(
void InspectableWebContentsViewViews::SetTitle(const base::string16& title) { void InspectableWebContentsViewViews::SetTitle(const base::string16& title) {
if (devtools_window_) { if (devtools_window_) {
GetDevToolsWindowDelegate()->SetWindowTitle(title); static_cast<DevToolsWindowDelegate*>(devtools_window_delegate_)
->SetWindowTitle(title);
devtools_window_->UpdateWindowTitle(); devtools_window_->UpdateWindowTitle();
} }
} }

View file

@ -10,14 +10,11 @@
namespace views { namespace views {
class WebView; class WebView;
class Widget; class Widget;
class WidgetDelegate;
} }
namespace brightray { namespace brightray {
namespace { // NOLINT
class DevToolsWindowDelegate;
}
class InspectableWebContentsImpl; class InspectableWebContentsImpl;
class InspectableWebContentsViewViews : public InspectableWebContentsView, class InspectableWebContentsViewViews : public InspectableWebContentsView,
@ -27,10 +24,6 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
InspectableWebContentsImpl* inspectable_web_contents_impl); InspectableWebContentsImpl* inspectable_web_contents_impl);
~InspectableWebContentsViewViews(); ~InspectableWebContentsViewViews();
DevToolsWindowDelegate* GetDevToolsWindowDelegate() const {
return devtools_window_delegate_;
}
// InspectableWebContentsView: // InspectableWebContentsView:
views::View* GetView() override; views::View* GetView() override;
views::View* GetWebView() override; views::View* GetWebView() override;
@ -61,7 +54,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
DevToolsContentsResizingStrategy strategy_; DevToolsContentsResizingStrategy strategy_;
bool devtools_visible_; bool devtools_visible_;
DevToolsWindowDelegate* devtools_window_delegate_; views::WidgetDelegate* devtools_window_delegate_;
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews); DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews);
}; };