Skip to content

Commit

Permalink
Clean up existing instances when updating the platform view (#119)
Browse files Browse the repository at this point in the history
* Clean up existing instances when updating the platform view

* This fix problem that occurs when a view is created on restart with
identical view id.

Signed-off-by: MuHong Byun <[email protected]>

* Refactor platform view channel which is related to clean up view resources

Signed-off-by: MuHong Byun <[email protected]>
  • Loading branch information
bwikbs authored and swift-kim committed Nov 14, 2021
1 parent 5a1917a commit 4ae46d7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
35 changes: 31 additions & 4 deletions shell/platform/tizen/channels/platform_view_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,30 @@ PlatformViewChannel::~PlatformViewChannel() {
}

void PlatformViewChannel::Dispose() {
ClearViewInstances();
ClearViewFactories();
}

void PlatformViewChannel::RemoveViewInstanceIfNeeded(int view_id) {
auto it = view_instances_.find(view_id);
if (view_id >= 0 && it != view_instances_.end()) {
auto view_instance = it->second;
view_instance->Dispose();
delete view_instance;
view_instances_.erase(it);
}
}

void PlatformViewChannel::ClearViewInstances() {
// Clean-up view_instances_
for (auto const& [view_id, view_instance] : view_instances_) {
view_instance->Dispose();
delete view_instance;
}
view_instances_.clear();
}

void PlatformViewChannel::ClearViewFactories() {
// Clean-up view_factories_
for (auto const& [view_type, view_factory] : view_factories_) {
view_factory->Dispose();
Expand Down Expand Up @@ -124,6 +142,7 @@ void PlatformViewChannel::HandleMethodCall(
FT_LOGI(
"PlatformViewChannel create viewType: %s id: %d width: %f height: %f ",
view_type.c_str(), view_id, width, height);
RemoveViewInstanceIfNeeded(view_id);

EncodableMap values = std::get<EncodableMap>(arguments);
EncodableValue value = values[EncodableValue("params")];
Expand Down Expand Up @@ -170,6 +189,17 @@ void PlatformViewChannel::HandleMethodCall(
} else {
result->Error("Can't find view id");
}
} else if (method == "dispose") {
int view_id = -1;
if (std::holds_alternative<int>(arguments)) {
view_id = std::get<int>(arguments);
};
if (view_id < 0 || view_instances_.find(view_id) == view_instances_.end()) {
result->Error("Can't find view id");
} else {
RemoveViewInstanceIfNeeded(view_id);
result->Success();
}
} else {
int view_id = -1;
if (!GetValueFromEncodableMap(arguments, "id", &view_id)) {
Expand All @@ -179,10 +209,7 @@ void PlatformViewChannel::HandleMethodCall(

auto it = view_instances_.find(view_id);
if (view_id >= 0 && it != view_instances_.end()) {
if (method == "dispose") {
it->second->Dispose();
result->Success();
} else if (method == "resize") {
if (method == "resize") {
double width = 0.0, height = 0.0;
if (!GetValueFromEncodableMap(arguments, "width", &width) ||
!GetValueFromEncodableMap(arguments, "height", &height)) {
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/tizen/channels/platform_view_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class PlatformViewChannel {
virtual ~PlatformViewChannel();

void Dispose();
void RemoveViewInstanceIfNeeded(int view_id);
void ClearViewInstances();
void ClearViewFactories();

std::map<std::string, std::unique_ptr<PlatformViewFactory>>& ViewFactories() {
return view_factories_;
Expand Down

0 comments on commit 4ae46d7

Please sign in to comment.